From f01076cc6edd123c3ed2c5e58f64a14a641bbace Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Thu, 4 Feb 2016 21:21:37 +0000 Subject: [PATCH] Fix couple of bugs in i18n when source string contains non-ASCII characters. --- src/Translation.cpp | 1 + translation_pot.py | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/Translation.cpp b/src/Translation.cpp index 30c1f97c..fa0c1223 100644 --- a/src/Translation.cpp +++ b/src/Translation.cpp @@ -52,6 +52,7 @@ CString CTranslation::Plural(const CString& sDomain, const CString& sContext, const std::locale& CTranslation::LoadTranslation(const CString& sDomain) { CString sLanguage = m_sLanguageStack.empty() ? "" : m_sLanguageStack.back(); + if (sLanguage.empty()) sLanguage = "C"; #ifdef HAVE_I18N // Not using built-in support for multiple domains in single std::locale // via overloaded call to .str() because we need to be able to reload diff --git a/translation_pot.py b/translation_pot.py index b253bd3d..2ce95831 100755 --- a/translation_pot.py +++ b/translation_pot.py @@ -32,20 +32,6 @@ args = parser.parse_args() pot_list = [] -# .cpp -main_pot = args.tmp_prefix + '_main.pot' -subprocess.check_call(['xgettext', - '--omit-header', - '-D', args.include_dir, - '-o', main_pot, - '--keyword=t:1,1t', '--keyword=t:1,2c,2t', - '--keyword=f:1,1t', '--keyword=f:1,2c,2t', - '--keyword=p:1,2,3t', '--keyword=p:1,2,4c,4t', - '--keyword=d:1,1t', '--keyword=d:1,2c,2t', -] + args.explicit_sources) -if os.path.isfile(main_pot): - pot_list.append(main_pot) - # .tmpl tmpl_pot = args.tmp_prefix + '_tmpl.pot' tmpl_uniq_pot = args.tmp_prefix + '_tmpl_uniq.pot' @@ -71,11 +57,30 @@ for tmpl_dir in args.tmpl_dirs: tmpl.append('') if tmpl: with open(tmpl_pot, 'w') as f: + print('msgid ""', file=f) + print('msgstr ""', file=f) + print(r'"Content-Type: text/plain; charset=UTF-8\n"', file=f) + print(r'"Content-Transfer-Encoding: 8bit\n"', file=f) + print(file=f) for line in tmpl: print(line, file=f) subprocess.check_call(['msguniq', '-o', tmpl_uniq_pot, tmpl_pot]) pot_list.append(tmpl_uniq_pot) +# .cpp +main_pot = args.tmp_prefix + '_main.pot' +subprocess.check_call(['xgettext', + '--omit-header', + '-D', args.include_dir, + '-o', main_pot, + '--keyword=t:1,1t', '--keyword=t:1,2c,2t', + '--keyword=f:1,1t', '--keyword=f:1,2c,2t', + '--keyword=p:1,2,3t', '--keyword=p:1,2,4c,4t', + '--keyword=d:1,1t', '--keyword=d:1,2c,2t', +] + args.explicit_sources) +if os.path.isfile(main_pot): + pot_list.append(main_pot) + # combine if pot_list: subprocess.check_call(['msgcat', '-o', args.output] + pot_list)