ReactNativeLocalization
ReactNativeLocalization copied to clipboard
string keys support
Hello, I don't know if it's done specially, but string keys are not supported. Wouldn't it be more logical to write:
Hello {title}, you have ${amount} on your balance
and then
strings.formatString(strings.foo, {title : 'Mr', amount: 10000000})
?
Yeah, could be a great alternative... If you'd like to implement surely I'll merge it.
Ill created a method for our projects. Currently it only supports ...params instead of an object.
const Strings = new LocalizedStrings(...);
export const substitute = (key, ...params)=> {
const translatedString = Strings[key];
if (params.length === 0) {
return translatedString;
} else {
let result = translatedString;
for (var x = 0; x < params.length - 1; x++) {
const search = '{' + x + '}';
while (result.indexOf(search) >= 0) {
result = result.replace(search, params[x + 1]);
}
}
return result;
}
};
I assign directly functions to the localized string elements, it works like breeze.
your_routine_has_triggered: (name) => `Your routine ${name} has been triggered 🎆`,
/* ... later... */
i18n.your_routine_has_triggered(routine.name)