CodeSOD: The Truth About Internationalization


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();
}

  }
[Advertisement] Continuously monitor your servers for configuration changes, and report when there’s configuration drift. Get started with Otter today!

https://ift.tt/2Gaza6g

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s