Article 3K7H2 CodeSOD: The Truth About Internationalization

CodeSOD: The Truth About Internationalization

by
snoofle
from The Daily WTF on (#3K7H2)

Booleans. One would think that simple true and false would be sufficient to represent all the possible values. However, even more than dates, they are one of the most difficult things to master in all of computer science. There are all manner of possible values and many different ways of comparing different entities.

Compounding everything is another dimension to boolean-ness: internationalization. After all, not every language uses English spellings of true and false. In high school, they made me take French, so it'd be vrai and faux. For most of us, we'd put the language-specific spelling in an application-phrases file, cache it and pick the appropriate spelling based upon the meaning of the required phrase. However, the underlying core values of truth/falsehood would still be programming-language-specific.

For most of us...

 class Internationalization { // These will index into the list of language-specific phrases public enum Phrases { TRUE, FALSE, ... }; private List<String> languageSpecificPhrases = new ArrayList<>(); public Internationalization() { // Load strings from configured language file into: languageSpecificPhrases... } public String getPhrase(Phrases phrase) { return languageSpecificPhrases.get(phrase.ordinal()). } public boolean getLanguageSpecificBooleanValueForTrue() { return true; } public boolean getLanguageSpecificBooleanValueForFalse() { return !getLanguageSpecificBooleanValueForTrue(); } }
otter-icon.png [Advertisement] Continuously monitor your servers for configuration changes, and report when there's configuration drift. Get started with Otter today! TheDailyWtf?d=yIl2AUoC8zAwURkerJeUQ0
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments