diff options
author | Thierry Crozat | 2016-11-08 02:01:30 +0000 |
---|---|---|
committer | Thierry Crozat | 2016-11-08 02:21:16 +0000 |
commit | 729264f11608a953cf875e17deb0729d659e9846 (patch) | |
tree | 77b1d6fef764c7037d30a1c089bad7af1e707aef /devtools/create_translations | |
parent | 015cf46cb01d9d4bb19028b49af57b34ae9ed2d8 (diff) | |
download | scummvm-rg350-729264f11608a953cf875e17deb0729d659e9846.tar.gz scummvm-rg350-729264f11608a953cf875e17deb0729d659e9846.tar.bz2 scummvm-rg350-729264f11608a953cf875e17deb0729d659e9846.zip |
I18N: Read language name preferably from custom 'X-Language-name' header
We have been abusing the 'Language' field to store the language name
that appears in the GUI for a translation. But this field is officially
supposed to store the language code, and most tools that edit po file
set it automatically. This has caused the language being changed by
mistake in the paste.
There is a provision for custom fields with a name starting with 'X-'
though. So Now, if defined, it will use the custom 'X-Language-name'
field, and fall back to 'Language' in case that custom field is not defined.
This should prevent the language being lost when not careful while
editing the translation.
Diffstat (limited to 'devtools/create_translations')
-rw-r--r-- | devtools/create_translations/po_parser.cpp | 16 | ||||
-rw-r--r-- | devtools/create_translations/po_parser.h | 1 |
2 files changed, 12 insertions, 5 deletions
diff --git a/devtools/create_translations/po_parser.cpp b/devtools/create_translations/po_parser.cpp index ecc3ba540c..f1ad833932 100644 --- a/devtools/create_translations/po_parser.cpp +++ b/devtools/create_translations/po_parser.cpp @@ -108,7 +108,7 @@ const char *PoMessageList::operator[](int index) const { } PoMessageEntryList::PoMessageEntryList(const char *lang) : - _lang(NULL), _charset(NULL), _langName(NULL), + _lang(NULL), _charset(NULL), _langName(NULL), _langNameAlt(NULL), _list(NULL), _size(0), _allocated(0) { _lang = new char[1 + strlen(lang)]; @@ -117,14 +117,15 @@ PoMessageEntryList::PoMessageEntryList(const char *lang) : _charset = new char[1]; _charset[0] = '\0'; // Set default langName to lang - _langName = new char[1 + strlen(lang)]; - strcpy(_langName, lang); + _langNameAlt = new char[1 + strlen(lang)]; + strcpy(_langNameAlt, lang); } PoMessageEntryList::~PoMessageEntryList() { delete[] _lang; delete[] _charset; delete[] _langName; + delete[] _langNameAlt; for (int i = 0; i < _size; ++i) delete _list[i]; delete[] _list; @@ -134,11 +135,16 @@ void PoMessageEntryList::addMessageEntry(const char *translation, const char *me if (*message == '\0') { // This is the header. // We get the charset and the language name from the translation string - char *str = parseLine(translation, "Language:"); + char *str = parseLine(translation, "X-Language-name:"); if (str != NULL) { delete[] _langName; _langName = str; } + str = parseLine(translation, "Language:"); + if (str != NULL) { + delete[] _langNameAlt; + _langNameAlt = str; + } str = parseLine(translation, "charset="); if (str != NULL) { delete[] _charset; @@ -236,7 +242,7 @@ const char *PoMessageEntryList::language() const { } const char *PoMessageEntryList::languageName() const { - return _langName; + return _langName ? _langName : _langNameAlt; } const char *PoMessageEntryList::charset() const { diff --git a/devtools/create_translations/po_parser.h b/devtools/create_translations/po_parser.h index a3b1c9a9d7..0c30517017 100644 --- a/devtools/create_translations/po_parser.h +++ b/devtools/create_translations/po_parser.h @@ -96,6 +96,7 @@ private: char *_lang; char *_charset; char *_langName; + char *_langNameAlt; PoMessageEntry **_list; int _size; |