Re:Yagni Exceptions (2021)
by matsemann on Monday October 17, 2022 @06:19AM
(#33231640)
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
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)
[ Parent
| on HN ]
Agreed. I don’t really know what problem these i18n tools solve that this doesn’t.
But 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.
Re:Yagni Exceptions (2021)
by iLoveOncall on Monday October 17, 2022 @07:41AM
(#33232228)
Your 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.
YAGNI ;) 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.
Re:Yagni Exceptions (2021)
by iLoveOncall on Monday October 17, 2022 @08:48AM
(#33232743)
> 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 > </.
Do 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?