r/FlutterDev • u/bramantec • Oct 06 '26
Discussion Never base logic on a translated string: a bug that hit 4 of my 5 languages
I ship a Flutter app (built with FlutterFlow, plus some Custom Code) in 5 languages. One option worked in English and silently broke in most of the others.
The user picks when something starts: "Tonight", "Tomorrow" or a custom time. My Custom Function decided the expiry by looking at the label they tapped. Simplified:
if (label.toLowerCase().contains('tonight')) { ... }In French, Spanish and Romanian the label is not "Tonight". The match never happened, so every "Tonight" expired after 2 hours. No crash, no error, nothing in the logs.
Italian had the mirror image: "In 1 hour" was matched against the English words "now" and "1h", so it created the thing starting immediately.
The fix was boring. The UI shows a translated label, but the logic only receives a stable code (tonight, tomorrow, pick), and the expiry is computed from the code.
An English-only test suite will never catch this, because the bug lives in the other languages.
Do you still compare strings anywhere in your logic, or is it enums and codes all the way? And what's the worst i18n bug you've shipped?
9
u/Cvette16 Oct 06 '26
I'm going to be honest with you, but this is a super beginner mistake. String comparing for logic is almost always a bad idea. You really should have stable value to compare on such as an enum or system code. Another mistake beginners make is always complaining off of an index. This is great until you have to change the order or make another change.
I have a feeling with the new generation of vibe coders, this simple issues are going to popup a lot.
4
u/tandycake Oct 06 '26
I'm sorry, but you have a shipped (production) app already translated in 5 languages, and you used English "tonight" and "now" as the underlying "values." That's pretty basic stuff.
I get it. It happens. But I don't think it's necessary to write a post about. I think it's a basic thing to do, even in an English-only app, especially in a language like Dart (unlike JavaScript) which have enums. It's like programming 101.
Is this just an AI post to get karma?
1
u/No_Boss_1911 Oct 06 '26
yeah dude hit the same thing from the wording side. got a done panel in english and german and the button text changed a few times cause a tester kept saying none of the options matched what he actually did. only thing that saved us was the logic never touching the label, it just stores done or not tried yet
the rule we cant break is that stored value never changes once its written, old check ins are already saved with it. so the copy can move whenever but the codes are basically frozen
how are you handling it in flutterflow, do the codes live in one place next to all 5 translations or does each language file own its own label?