Add localisation files

This commit is contained in:
Lei Nelissen
2020-11-02 22:43:11 +01:00
parent 6a1d75c27c
commit 0df9d4a621
6 changed files with 130 additions and 2 deletions

View File

@@ -4,13 +4,25 @@ module.exports = {
[
'module-resolver',
{
// root: ['./src'],
root: ['.'],
extensions: [
'.ios.ts',
'.android.ts',
'.ts',
'.ios.tsx',
'.android.tsx',
'.tsx',
'.jsx',
'.js',
'.json',
],
alias: {
store: './src/store',
components: './src/components',
utility: './src/utility',
screens: './src/screens',
assets: './src/assets',
'@localisation': './src/localisation',
CONSTANTS: './src/CONSTANTS',
}
}

43
src/localisation/index.ts Normal file
View File

@@ -0,0 +1,43 @@
import i18n from 'i18n-js';
import { findBestAvailableLanguage } from 'react-native-localize';
import { LocaleKeys } from './types';
// Lazy loaders for locale
const localeGetters: Record<string, () => object> = {
en: () => require('./lang/en.json'),
fr: () => require('./lang/fr.json'),
};
// Have RNLocalize pick the best locale from the languages on offer
const locale = findBestAvailableLanguage(Object.keys(localeGetters));
// Check if the locale is correctly picked
if (!locale || !locale.languageTag) {
throw new Error('Invalid locale selected');
}
// Set the key-value pairs for the different languages you want to support.
i18n.translations = {
en: localeGetters.en(),
};
// If the locale is not english, we add it to the translations key s well
if (locale.languageTag !== 'en') {
i18n.translations[locale.languageTag] = localeGetters[locale.languageTag as string]();
}
// Set the locale once at the beginning of your app.
i18n.locale = locale.languageTag;
// Fallback to the default language for missing translation strings
i18n.fallbacks = true;
/**
* An i18n Typescript helper with autocomplete for the key argument
* @param key string
*/
export function t(key: LocaleKeys) {
return i18n.t(key);
}
export default i18n;

View File

@@ -0,0 +1,27 @@
{
"play-next": "Play Next",
"play-album": "Play Album",
"queue": "Queue",
"add-to-queue": "Add to Queue",
"clear-queue": "Clear Queue",
"no-results": "No results...",
"album": "Album",
"all-albums": "All Albums",
"search": "Search",
"music": "Music",
"now-playing": "Now Playing",
"onboarding-welcome": "Welcome!",
"onboarding-intro": "Jellyfin Audio Player will allow you to stream your music library from anywhere, with full support for background audio and casting.",
"onboarding-cta": "In order to get started, you need a Jellyfin server. Click the button below to enter your Jellyfin server address and login to it.",
"set-jellyfin-server": "Set Jellyfin Server",
"set-jellyfin-server-instruction": "Please enter your Jellyfin server URL. Make sure to include the protocol and port",
"settings": "Settings",
"jellyfin-library": "Jellyfin Library",
"jellyfin-server-url": "Jellyfin Server URL",
"jellyfin-access-token": "Jellyfin Access Token",
"jellyfin-user-id": "Jellyfin User ID",
"setting-cache": "Cache",
"setting-cache-description": "If you have updated your Jellyfin library, but the app is holding on to cached assets, you can forcefully clear the cache using this button. This will force the app to fetch the library from scratch.",
"reset-cache": "Reset Cache",
"recent-albums": "Recent Albums"
}

View File

@@ -0,0 +1,19 @@
{
"play-next": "Lire ensuite",
"play-album": "Jouer l'album",
"add-to-queue": "Ajouter à la file d'attente",
"clear-queue": "Vider la fille d'attente",
"no-results": "Pas de résultats...",
"album": "Album",
"onboarding-welcome": "Bienvenue !",
"onboarding-intro": "Jellyfin Audio Player vous permettra de diffuser votre bibliothèque musicale de n'importe où, avec un support de la lecture en arrière plan et la diffusion à distance.",
"onboarding-cta": "Pour utiliser Jellyfin Audio Player, vous avez besoin d'un serveur Jellyfin. Cliquez sur le bouton ci-dessous pour entrer l'adresse de votre serveur Jellyfin et vous y connecter.",
"set-jellyfin-server": "Configurer le serveur Jellyfin",
"set-jellyfin-server-instruction": "Veuillez entrer l'URL de votre serveur Jellyfin. Assurez-vous d'inclure le protocole et le port",
"jellyfin-server-url": "URL du serveur Jellyfin",
"jellyfin-access-token": "Jeton d'accès à la Jellyfin",
"jellyfin-user-id": "ID utilisateur Jellyfin",
"setting-cache": "Cache",
"setting-cache-description": "Si vous avez mis à jour votre bibliothèque Jellyfin mais que l'application conserve toujours des ressources en cache, vous pouvez vider le cache en utilisant ce bouton. Cela forcera l'application à récupérer lintégralité de bibliothèque.",
"reset-cache": "Réinitialiser le cache"
}

25
src/localisation/types.ts Normal file
View File

@@ -0,0 +1,25 @@
export type LocaleKeys = 'play-next'
| 'play-album'
| 'queue'
| 'add-to-queue'
| 'clear-queue'
| 'no-results'
| 'album'
| 'all-albums'
| 'search'
| 'music'
| 'now-playing'
| 'onboarding-welcome'
| 'onboarding-intro'
| 'onboarding-cta'
| 'set-jellyfin-server'
| 'set-jellyfin-server-instruction'
| 'settings'
| 'jellyfin-library'
| 'jellyfin-server-url'
| 'jellyfin-access-token'
| 'jellyfin-user-id'
| 'setting-cache'
| 'setting-cache-description'
| 'reset-cache'
| 'recent-albums'

View File

@@ -38,7 +38,9 @@
/* Module Resolution Options */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"baseUrl": "./src", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
"paths": {
"@localisation": ["./localisation"]
}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */