In order to import language files that come from an API, spreadsheet or JSON-files, typesafe-i18n provides an importer functionality.
There exists an official plugin for Inlang. It allows you to use typesafe-i18n together with the tooling Inlang provides. You can find it here.
You have to write your own logic to get the data, then map it to a dictionary-representation and then call the storeTranslationToDisk function. Here is an example how this could look like:
See here on more information how to set up typesafe-i18n.
npm install typesafe-i18nAn example implementation can be seen in the import.ts-file.
you need to run this script during development or as a CI-process and not at runtime. Create an own file with the implementation and run it with
tsxor something similar.
To run this example execute following command in your terminal:
npm run i18n:importYou should see a successful log message show up in your terminal.
In a real world implementation you would have to write your own logic to fetch the data from a service.
Please share your implementation in a PR.
typesafe-i18nwants to provide built-in importer-packages in the future.
The typesafe-i18n/importer package provides following:
interface ImportLocaleMapping {
locale: string
translations: BaseTranslation | BaseTranslation[]
namespaces?: string[]
}Can be used to write translations for a single locale to disk. If locale matches the baseTranslation the generator will automatically run after the import. If you don't want to run the generator after the translations are being imported, set generateTypes to false.
(mapping: ImportLocaleMapping, generateTypes?: boolean) => Promise<Locale>Can be used to write translations for multiple locales to disk. If one of entry's locale matches the baseTranslation the generator will automatically run after the import. If you don't want to run the generator after the translations are being imported, set generateTypes to false.
(mappings: ImportLocaleMapping[], generateTypes?: boolean) => Promise<Locales[]>