mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-11 19:14:51 +00:00
support language variants like german (old spelling) or british english
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38029 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
1348aa03d7
commit
5bf72d6dca
@ -164,6 +164,10 @@ Translation de
|
|||||||
"Table" "Tabelle"
|
"Table" "Tabelle"
|
||||||
End
|
End
|
||||||
|
|
||||||
|
Translation de_alt
|
||||||
|
"Conclusion" "Schlußfolgerung"
|
||||||
|
End
|
||||||
|
|
||||||
Translation el
|
Translation el
|
||||||
"Acknowledgement" "Μνεία"
|
"Acknowledgement" "Μνεία"
|
||||||
"Algorithm" "Αλγόριθμος"
|
"Algorithm" "Αλγόριθμος"
|
||||||
|
100
src/Language.cpp
100
src/Language.cpp
@ -194,9 +194,10 @@ bool Language::read(Lexer & lex)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Language::readLayoutTranslations(Lexer & lex)
|
namespace {
|
||||||
|
|
||||||
|
bool readTranslations(Lexer & lex, Language::TranslationMap & trans)
|
||||||
{
|
{
|
||||||
layoutTranslations_.clear();
|
|
||||||
while (lex.isOK()) {
|
while (lex.isOK()) {
|
||||||
if (lex.checkFor("End"))
|
if (lex.checkFor("End"))
|
||||||
break;
|
break;
|
||||||
@ -206,15 +207,44 @@ bool Language::readLayoutTranslations(Lexer & lex)
|
|||||||
if (!lex.next(true))
|
if (!lex.next(true))
|
||||||
return false;
|
return false;
|
||||||
docstring const val = lex.getDocString();
|
docstring const val = lex.getDocString();
|
||||||
layoutTranslations_[key] = val;
|
trans[key] = val;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum Match{NoMatch, ApproximateMatch, ExactMatch};
|
||||||
|
|
||||||
void Language::readLayoutTranslations(Language const & lang)
|
Match match(string const & code, Language const & lang)
|
||||||
{
|
{
|
||||||
layoutTranslations_ = lang.layoutTranslations_;
|
// we need to mimic gettext: code can be a two-letter code, which
|
||||||
|
// should match all variants, e.g. "de" should match "de_DE",
|
||||||
|
// "de_AT" etc.
|
||||||
|
// special case for chinese:
|
||||||
|
// simplified => code == "zh_CN", langcode == "zh_CN"
|
||||||
|
// traditional => code == "zh_TW", langcode == "zh_CN"
|
||||||
|
string const variety = lang.variety();
|
||||||
|
string const langcode = variety.empty() ?
|
||||||
|
lang.code() : lang.code() + '_' + variety;
|
||||||
|
string const name = lang.lang();
|
||||||
|
if ((code == langcode && name != "chinese-traditional") ||
|
||||||
|
(code == "zh_TW" && name == "chinese-traditional"))
|
||||||
|
return ExactMatch;
|
||||||
|
if ((code.size() == 2 && langcode.size() > 2 &&
|
||||||
|
code + '_' == langcode.substr(0, 3)))
|
||||||
|
return ApproximateMatch;
|
||||||
|
return NoMatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Language::readLayoutTranslations(Language::TranslationMap const & trans, bool replace)
|
||||||
|
{
|
||||||
|
TranslationMap::const_iterator const end = trans.end();
|
||||||
|
for (TranslationMap::const_iterator it = trans.begin(); it != end; ++it)
|
||||||
|
if (replace ||
|
||||||
|
layoutTranslations_.find(it->first) == layoutTranslations_.end())
|
||||||
|
layoutTranslations_[it->first] = it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -269,6 +299,12 @@ void Languages::readLayoutTranslations(support::FileName const & filename)
|
|||||||
Lexer lex;
|
Lexer lex;
|
||||||
lex.setFile(filename);
|
lex.setFile(filename);
|
||||||
lex.setContext("Languages::read");
|
lex.setContext("Languages::read");
|
||||||
|
|
||||||
|
// 1) read all translations (exact and approximate matches) into trans
|
||||||
|
typedef std::map<string, Language::TranslationMap> TransMap;
|
||||||
|
TransMap trans;
|
||||||
|
LanguageList::iterator const lbeg = languagelist.begin();
|
||||||
|
LanguageList::iterator const lend = languagelist.end();
|
||||||
while (lex.isOK()) {
|
while (lex.isOK()) {
|
||||||
if (!lex.checkFor("Translation")) {
|
if (!lex.checkFor("Translation")) {
|
||||||
if (lex.isOK())
|
if (lex.isOK())
|
||||||
@ -278,40 +314,38 @@ void Languages::readLayoutTranslations(support::FileName const & filename)
|
|||||||
if (!lex.next(true))
|
if (!lex.next(true))
|
||||||
break;
|
break;
|
||||||
string const code = lex.getString();
|
string const code = lex.getString();
|
||||||
// we need to mimic gettext: code can be a two-letter code,
|
bool readit = false;
|
||||||
// which should match all variants, e.g. "de" should match
|
for (LanguageList::iterator lit = lbeg; lit != lend; ++lit) {
|
||||||
// "de_DE", "de_AT" etc.
|
if (match(code, lit->second) != NoMatch) {
|
||||||
Language * firstlang = 0;
|
if (readTranslations(lex, trans[code]))
|
||||||
LanguageList::iterator const end = languagelist.end();
|
readit = true;
|
||||||
for (LanguageList::iterator it = languagelist.begin(); it != end; ++it) {
|
else
|
||||||
// special case for chinese:
|
lex.printError("Could not read layout "
|
||||||
// simplified => code == "zh_CN", langcode == "zh_CN"
|
"translations for language "
|
||||||
// traditional => code == "zh_TW", langcode == "zh_CN"
|
"`" + code + "'");
|
||||||
string const langcode = it->second.code();
|
break;
|
||||||
string const name = it->second.lang();
|
|
||||||
if ((code == langcode && name != "chinese-traditional") ||
|
|
||||||
(code == "zh_TW" && name == "chinese-traditional") ||
|
|
||||||
(code.size() == 2 && langcode.size() > 2 &&
|
|
||||||
code + '_' == langcode.substr(0, 3))) {
|
|
||||||
if (firstlang)
|
|
||||||
it->second.readLayoutTranslations(*firstlang);
|
|
||||||
else {
|
|
||||||
if (!it->second.readLayoutTranslations(lex)) {
|
|
||||||
lex.printError("Could not read "
|
|
||||||
"layout translations "
|
|
||||||
"for language `" +
|
|
||||||
code + "'");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
firstlang = &(it->second);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!firstlang) {
|
if (!readit) {
|
||||||
lex.printError("Unknown language `" + code + "'");
|
lex.printError("Unknown language `" + code + "'");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2) merge all translations into the languages
|
||||||
|
// exact translations overwrite approximate ones
|
||||||
|
TransMap::const_iterator const tbeg = trans.begin();
|
||||||
|
TransMap::const_iterator const tend = trans.end();
|
||||||
|
for (TransMap::const_iterator tit = tbeg; tit != tend; ++tit) {
|
||||||
|
for (LanguageList::iterator lit = lbeg; lit != lend; ++lit) {
|
||||||
|
Match m = match(tit->first, lit->second);
|
||||||
|
if (m == NoMatch)
|
||||||
|
continue;
|
||||||
|
lit->second.readLayoutTranslations(tit->second,
|
||||||
|
m == ExactMatch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,9 +78,9 @@ public:
|
|||||||
///
|
///
|
||||||
bool readLanguage(Lexer & lex);
|
bool readLanguage(Lexer & lex);
|
||||||
///
|
///
|
||||||
bool readLayoutTranslations(Lexer & lex);
|
typedef std::map<std::string, docstring> TranslationMap;
|
||||||
///
|
///
|
||||||
void readLayoutTranslations(Language const & lang);
|
void readLayoutTranslations(TranslationMap const & trans, bool replace);
|
||||||
// for the use in std::map
|
// for the use in std::map
|
||||||
friend bool operator<(Language const & p, Language const & q);
|
friend bool operator<(Language const & p, Language const & q);
|
||||||
private:
|
private:
|
||||||
@ -115,8 +115,6 @@ private:
|
|||||||
///
|
///
|
||||||
bool translated_;
|
bool translated_;
|
||||||
///
|
///
|
||||||
typedef std::map<std::string, docstring> TranslationMap;
|
|
||||||
///
|
|
||||||
TranslationMap layoutTranslations_;
|
TranslationMap layoutTranslations_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user