I currently have a
languages.js set up as such:
var MaterialProperties = 0; var YieldStrength = 1; var OtherPhrases = 2; //continue to list other phrases - there are 40+ var English = [ "Material Properties", "Yield Strength", "Other Phrases" ]; var Chinese = [ // Chinese string that means "Material Properties", // Chinese string that means "Yield Strength", // Other phrases in Chinese ]; var SelectedLanguage = English; //default
Then I have the user select via dropdown box the language they would like, calling
setLanguage(selected_language), which sets
SelectedLanguage to either "English" or "Chinese", depending on the value of the dropbox selection.
Everywhere in my HTML where it should read "Material Strength" (or corresponding string in Chinese), I reference this as
SelectedLanguage[MaterialProperties], which is the same as saying
Chinese, which returns the correct string.
Is there a better, more efficient, cleaner way to do this?