Hi,
I made an autoreply app for rocket.chat. Currently the text output is in German, but I like to use i18n for localization. Because of the slash command I have already a de.i18n.json file, but I don’t know how to access additional entries from within the .app file.
Can someone help me with that problem?
thanks in advance
Frank
Unfortunately, at the moment you cannot use i18n in App’s source.
I have my own implementation for i18n, maybe these guide help:
Put all localization strings into ts file
Create your own localizer
Read the server setting to decide which language you should use
import { LocalizationKey, transferResource } from "../constants/resources";
import { LOCALIZATION_ARGS_REGEX } from "../constants/regex";
export type Localizer = (label: LocalizationKey, args?: Record<string, string>) => string;
export const getLocalizer = (language = "en"): Localizer => {
const localizationResource = transferResource[language] || transferResource.en;
return (label: LocalizationKey, args?: Record<string, string>) => {
return localizationResource[label].replace(LOCALIZATION_ARGS_REGEX, (match, p1) => args?.[p1] || "");
};
};
here is my implementation for the localizer
1 Like
opened 08:58AM - 10 Jan 22 UTC
Apps may need to read its own localization resource in order to provide the mult… i-language feature.
There're some use cases the apps may need that feature:
* Sending messages with different language
* Logging with different languages
* Providing i18n args for the buttons/settings description/message actions
opened 02:45AM - 01 Dec 21 UTC
Apps may need to read their own files. It allows the apps to have more assets an… d abilities. Some possible use cases:
* Storing text asset files
* Storing image/video files
* Storing template file (message template, response template)
These are the issues that u can track
1 Like
sorry, this is not helping me because I don’t see how you check which language is selected.
getLocalizer method is an curried function. which accept the language param and produce the localizer
const localizer = getLocalizer(language);
localizer(key);
language depends on your usage.
with me, I set it to server language:
const language = await read.getEnvironmentReader().getServerSettings().getValueById("Language");
await read.getEnvironmentReader().getServerSettings().getValueById("Language");
is always empty. Seems “Language” is not set.
ok, if the language is set to default, then it’s empty, otherwise I get an result.
Do you know how to get the users language?
I tried it with:
await read.getUserReader().getById(context.getSender().id);
But there is no language value.
thats bc u set language to default.
to can fallback to en in the get language statement