+
+ // Read layout translations
+ FileName const path = libFileSearch(string(), "layouttranslations");
+ readLayoutTranslations(path);
+}
+
+
+void Languages::readLayoutTranslations(support::FileName const & filename)
+{
+ Lexer lex;
+ lex.setFile(filename);
+ 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()) {
+ if (!lex.checkFor("Translation")) {
+ if (lex.isOK())
+ lex.printError("Unknown layout translation tag `$$Token'");
+ break;
+ }
+ if (!lex.next(true))
+ break;
+ string const code = lex.getString();
+ bool readit = false;
+ for (LanguageList::iterator lit = lbeg; lit != lend; ++lit) {
+ if (match(code, lit->second) != NoMatch) {
+ if (readTranslations(lex, trans[code]))
+ readit = true;
+ else
+ lex.printError("Could not read layout "
+ "translations for language "
+ "`" + code + "'");
+ break;
+ }
+ }
+ if (!readit) {
+ lex.printError("Unknown language `" + code + "'");
+ 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);
+ }
+ }
+