mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-31 16:03:24 +00:00
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.
This commit is contained in:
parent
015cf46cb0
commit
729264f116
@ -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 {
|
||||
|
@ -96,6 +96,7 @@ private:
|
||||
char *_lang;
|
||||
char *_charset;
|
||||
char *_langName;
|
||||
char *_langNameAlt;
|
||||
|
||||
PoMessageEntry **_list;
|
||||
int _size;
|
||||
|
Loading…
x
Reference in New Issue
Block a user