Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.arch.embedded > #27234
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | comp.arch.embedded, comp.lang.c |
| Subject | Re: Multi-language support on embedded plarforms |
| Date | 2017-09-05 10:43 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <oolo3c$9f9$1@dont-email.me> (permalink) |
| References | <ooljr9$2kp$1@dont-email.me> |
Cross-posted to 2 groups.
On 05/09/17 09:30, pozz wrote:
> [This message is posted to comp.arch.embedded and comp.lang.c]
>
> Just for reference, an embedded platform based on a MCU with integrated
> Flash, for example a Cortex-Mx device.
> Here I consider only western languages (left-to-right and european
> chars, english, french, german, spanish and so on).
>
> The main problem is the translation of strings, maybe 10-100 strings.
>
> I know something about gettext package that can't be used in those
> embeded platforms. However I like the approach of gettext.
>
> print_to_display(x, y, "Hello world!");
>
> is simply changed in:
>
> #include <gettext.h>
> ...
> print_to_display(x, y, _("Hello world!"));
>
> In this way, the code stays highly readble as before introducing the
> multi-language support. If a member of a structure needs a string, it is
> a char * as usual.
>
> The solution I found in embedded platforms is to use an array of array
> of strings: one index for the string and one index for the language.
>
> enum lang_t { ENGLISH, ITALIAN, LANG_N };
> enum string_t { STR_HELLO_WORLD, STR_HOW_ARE_YOU };
>
> const char *strings[STRING_N][LANG_N] = {
> { // STR_HELLO_WORLD
> { "Hello world!", "Ciao mondo" }
> },
> { // STR_HOW_ARE_YOU
> { "How are you?", "Come stai?" }
> },
> };
>
> static enum lang_t lang = ENGLISH;
>
> const char *_(int string_idx) {
> return strings[string_idx][lang];
> }
>
> void set_language(enum lang_t new_language) {
> lang = new_language;
> }
>
>
> I don't like too much this approach for two reasons.
> The first, the line:
>
> print_to_display(x, y, _(STR_HELLO_WORLD));
>
> is much less readable than
>
> print_to_display(x, y, _("Hello world!"));
>
>
> The second, I need to change the type of some members/variables from
> char * to int:
>
> struct mystruct {
> int title; // Instead of char *title
> ...
> };
>
>
> Another approach I'm thinking is to embed all the translations in the
> string, using a separator character that can't be used in normal strings.
>
> print_to_display(x, y, _("Hello world!|Ciao Mondo!"));
>
> The _() function will search the translated string based on the current
> language. If he can't find, it could return the first translation
> (english).
>
> This approach has some disadvantages. It's difficult to exclude one
> language from the build. If the languages are more than a couple, the
> strings will be very long. The order of the translations (first english,
> than italian, ...) is important and you have to remember it for every
> string.
>
>
> What approach do you use?
I think if you are looking for a pure C approach, and you want to keep
it efficient, then using the enumerated type as an index is the best choice.
But rather than writing all the strings directly in C, I would keep
track of them in a spreadsheet saved in tab delimited format, and use a
little script to turn it into a C header file declaring the enum, and a
C source file initialising the array. It just makes it easier to keep
track of everything, and saves a great deal of effort when you need to
get someone else to make the translation strings.
Back to comp.arch.embedded | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Multi-language support on embedded plarforms pozz <pozzugno@gmail.com> - 2017-09-05 09:30 +0200
Re: Multi-language support on embedded plarforms David Brown <david.brown@hesbynett.no> - 2017-09-05 10:43 +0200
Re: Multi-language support on embedded plarforms Robert Wessel <robertwessel2@yahoo.com> - 2017-09-05 09:56 -0500
Re: Multi-language support on embedded plarforms Ian Collins <ian-news@hotmail.com> - 2017-09-06 07:50 +1200
Re: Multi-language support on embedded plarforms Robert Wessel <robertwessel2@yahoo.com> - 2017-09-05 17:11 -0500
Re: Multi-language support on embedded plarforms Keith Thompson <kst-u@mib.org> - 2017-09-05 15:17 -0700
Re: Multi-language support on embedded plarforms Robert Wessel <robertwessel2@yahoo.com> - 2017-09-05 19:19 -0500
Re: Multi-language support on embedded plarforms raltbos@xs4all.nl (Richard Bos) - 2017-09-09 12:37 +0000
Re: Multi-language support on embedded plarforms Robert Wessel <robertwessel2@yahoo.com> - 2017-09-09 16:16 -0500
Re: Multi-language support on embedded plarforms raltbos@xs4all.nl (Richard Bos) - 2017-09-15 17:17 +0000
Re: Multi-language support on embedded plarforms Allan Herriman <allanherriman@hotmail.com> - 2017-09-06 11:27 +0000
Re: Multi-language support on embedded plarforms Paul <paul@pcserviceselectronics.co.uk> - 2017-09-05 10:04 +0100
Re: Multi-language support on embedded plarforms Theo Markettos <theom+news@chiark.greenend.org.uk> - 2017-09-06 10:55 +0100
Re: Multi-language support on embedded plarforms Phil Hobbs <pcdhSpamMeSenseless@electrooptical.net> - 2017-09-05 17:00 -0400
Re: Multi-language support on embedded plarforms Keith Thompson <kst-u@mib.org> - 2017-09-07 10:55 -0700
Re: Multi-language support on embedded plarforms scott@slp53.sl.home (Scott Lurndal) - 2017-09-07 18:41 +0000
Re: Multi-language support on embedded plarforms pozz <pozzugno@gmail.com> - 2017-09-08 11:33 +0200
Re: Multi-language support on embedded plarforms bartc <bc@freeuk.com> - 2017-09-08 11:32 +0100
Re: Multi-language support on embedded plarforms David Brown <david.brown@hesbynett.no> - 2017-09-08 13:37 +0200
Re: Multi-language support on embedded plarforms bartc <bc@freeuk.com> - 2017-09-08 14:48 +0100
Re: Multi-language support on embedded plarforms David Brown <david.brown@hesbynett.no> - 2017-09-08 16:45 +0200
Re: Multi-language support on embedded plarforms Richard Damon <Richard@Damon-Family.org> - 2017-09-08 10:43 -0400
Re: Multi-language support on embedded plarforms Mel Wilson <mwilson@the-wire.com> - 2017-09-08 17:33 +0000
csiph-web