Typescripts decorator which helps in:
- All translations in one place with its key
Go To Definition
support- Parameterized translations
- Missing translation generation for quick prototyping
Install dependencies with npm:
npm i mustafah/translations
import Translations from 'translations';
enum Languages {
Arabic,
English,
German,
French
}
import { configTranslations } from 'translations';
configTranslations({ languagesEnum: Languages });
@Component({ ... })
export class Component {
@Translations()
t = {
HelloWorld: [
'مرحباً بالعالم',
'Hello World',
'Hallo Welt',
'Bonjour le Monde'
]
};
}
setTranslationLanguage(Languages.English);
@Translations()
t: any = {
WelcomeTo: (country) => [
`أهلاً بك في ${country}`,
`Welcome to ${country}`,
`Willkommen in ${country}`,
`Bienvenue en ${country}`
],
// Countries
Egypt: ['مصر', 'Egypt', 'Ägypten', 'Égypte'],
Germany: ['ألمانيا', 'Germany', 'Deutschland', 'Allemagne']
};
setTranslationLanguage(Languages.English);
console.log(this.t.WelcomeTo(this.t.Egypt));
// Welcome to Egypt
setTranslationLanguage(Languages.German);
console.log(this.t.WelcomeTo(this.t.Germany));
// Willkommen in Deutschland
Thank you 🙏