Skip to content

Commit

Permalink
feat: update settings.service to display Pokémon names based on selec…
Browse files Browse the repository at this point in the history
…ted language

- Enhanced settings.service to dynamically display Pokémon names according to the selected language.
- Integrated language-based name display across relevant components.
- Updated JSDocs to reflect the new functionality.
  • Loading branch information
mariokreitz committed Sep 18, 2024
1 parent 68ca992 commit 92be6a4
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/app/components/pokemon-card/pokemon-card.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { TitleCasePipe, DecimalPipe } from '@angular/common';
import { Component, Input } from '@angular/core';
import { PokemonImageComponent } from './pokemon-image/pokemon-image.component';
import { Pokemon } from '../../../types/pokedex';
import { SettingsService } from '../../services/settings.service';

/**
* A component that displays a Pokémon card.
Expand All @@ -25,6 +26,7 @@ import { Pokemon } from '../../../types/pokedex';
styleUrls: ['./pokemon-card.component.scss'],
})
export class PokemonCardComponent {
constructor(private settingsService: SettingsService) {}
/**
* The Pokémon to display in the card.
*
Expand All @@ -43,12 +45,19 @@ export class PokemonCardComponent {
}

/**
* Retrieves the name of the Pokémon.
* Retrieves the name of the Pokémon in the current language.
*
* @returns {string} The name of the Pokémon.
* If the Pokémon has a name in the current language, that name is returned.
* Otherwise, the Pokémon's default name is returned.
*
* @return {string} The name of the Pokémon in the current language, or the default name if no translation is available.
*/
get name(): string {
return this.Pokemon.name;
return (
this.Pokemon.names.find(
(name) => name.language.name === this.settingsService.getLanguage()
)?.name || this.Pokemon.name
);
}

/**
Expand Down

0 comments on commit 92be6a4

Please sign in to comment.