I'm thinking to use a function call to get a string, with an index of the string as a parameter.
The main issue is how to save all the strings in Flash memory in an efficient and simple way. A simple two-indices (one for the language and one of the string) const array?
I like the solution of gettext that introduces _() function and the code stays readable:
printf(_("How are you?"));
Another possibility is to maintain all strings in a spreadsheet, write a macro or two in the spreadsheet to export all the strings with unique enumerated values for each string. Some advantages:
* spreadsheets may also contain meta information on each string, which will help the translators create more precise translations. The translators will know how to receive and process a spreadsheet.
* spreadsheets may also list any space limits for individual strings, again to help the translators create translations that fit in constrained space.
* With a unique enum for each string, it avoids the string comparison overhead.
* With enums, you avoid the issue of what happens when the string changes, with the _() approach, ideally must change the code too. (might anyhow if the meaning changed dramatically). This is a bit closer to the DRY principle, which can quickly become a critical issue to consider when maintaining strings for many languages.
That being said, I also like the "look" of the _() approach.
This is trimmed down from a nice post that took me 1/2 an hour to write, because the system said that I was logged in, then lost my post at the end with a short nastygram about needing to be logged in to submit posts. Talk to @Stephan if you're upset.
This is a synopsis:
- If you use the "How are you?" approach, figure out how to put those strings into a segment by themselves (the gnu tools __attribute__ facility will be handy) for later machine-extraction -- otherwise your code will not be goof-proof.
- Use Matt's spreadsheet idea. Either use the spreadsheet as a human-generated table that generates the STR_HOW_ARE_YOU macros, or as a partially-machine-generated table if you es the "How are you?" approach.
- If you go with STR_HOW_ARE_YOU, the macro can be an array of indexes into the rows or columns of a table of phrases, with the actual phrase selected by some global language index.
- If I went with "How are you?", I would have a table of pointers to translated phrases, (languages - 1) x (phrase count), and I would use a hash function to figure out which to use. I'd find or invent some fairly memory-efficient hash, even at the expense of some processor time. My hash table would probably have limited depth, with overruns just turning into a linear search that spills out onto the next row of indexes.
Sorry about the brevity.
sorry to read that you lost 30 minutes of your time. Really curious to understand what might have gone wrong, what might have logged you out between the time you started to write and the time you tried to submit your post. Was it the first time that this happened to you?
Thanks and sorry again.
Yes, first time -- I logged on once with the wrong password, logged on again with the right one, the thing allowed me to open an edit window, then refused the edit when I hit "reply".
I was probably as grumpy as I sounded when I wrote it, but shouldn't have been -- or at least don't have a right to, until I write perfect code.
Maybe your login session timed out? I think that happened to me once. I tend to not trust websites so I'll select and copy everything I wrote before clicking Submit. That way if anything goes wrong, I can log back in and paste it back.
Tim, @jorick was right, it so happens that the PHP session timeout variable was set to 1440 seconds (24 minutes). I increased it to 7200 seconds (2 hours) and hopefully this should prevent the session timeout from happening again. But I do recommend to use a local editor to compose long replies and then copy/paste, just to make sure.. Sorry again for the trouble, I really hate that you lost 30 minutes of your time because of this.