4 ms·
You don't need to bake in a complete i18n solution, though. Just create a simple map of keys->strings, and then a function ala getStringForKey(key, languag
by matsemann 4y ago
You don't need to bake in a complete i18n solution, though. Just create a simple map of keys->strings, and then a function ala
getStringForKey(key, language) {
return map[key]
and then whenever you actually need it, just expand on it. But at least you then have all strings in one place, and a common way of accessing them. (And easy lookup of all places using these strings)
- sonthonax 4y agoAgreed. I don’t really know what problem these i18n tools solve that this doesn’t.
- matsemann 4y agoBut if you end up in a situation where i18n tools are needed, this function can be the single entry point anyways, abstracting most of it away.
- iLoveOncall 4y agoYour function doesn't solve any of the issues I mentioned, you still need to switch to another file, still need to think of a sufficiently explicit key, still need to handle plurals and masculine / feminine variations, etc.
- matsemann 4y agoYAGNI ;) You can skip all those things the first time. You don't need to have a separate file or anything. Just have a stupid function returning its input or whatever. The important part is having an entry-point, and an easy way to find all relevant uses in the future. You could then later, when i18n is needed, write a script finding those usages and automatically extract them. That's what I've done once before. And it was a thousand times easier than the time before where we had to hunt through all of frontend, backend, cms etc. to find stuff.
- iLoveOncall 4y ago> The important part is having an entry-point, and an easy way to find all relevant uses in the future. You already have it, it's everything that's in between {{ }} and > </.
- matsemann 4y agoDo you want to translate numbers between ><? What about alt-texts not in those tags? Things passed as props multiple layers? What about strings coming from backend? Do you read some things from the environment?