Usage
With @inlang/sdk-js
you get many useful functions to help you implement internationalization in your application. This is a list of all the functions, what they provide and how to use them.
i
Use the inlang function (i
) to get a language dependent text. The function takes the key of the text as a parameter and returns the string according to the current language.
Example
language
The language
variable contains the current selected language.
Example
languages
The languages
array returns all languages that are available for this application.
Example
referenceLanguage
The referenceLanguage
function returns the reference language that is used to translate the texts.
Example
switchLanguage
The switchLanguage
function allows you to change the language of the application. The function takes the language as a parameter and returns a promise that resolves when the language has been changed.
Example
loadResource
The loadResource
function allows you to load the resource file for a specific language. The function takes the language as a parameter and returns a promise that resolves when the resource file has been loaded.
Resources are loaded automatically, but you can already preload them to reduce the loading time when switching the language.
Example
Is something unclear or do you have questions? Reach out to us in our Discord channel or open a Discussion or an Issue on Github.