Make templates localizable (Closes #100)

This commit is contained in:
Twan van Laarhoven
2020-10-03 14:38:39 +02:00
parent f2ae3ae43b
commit c7377303cf
23 changed files with 155 additions and 63 deletions
+21
View File
@@ -8,6 +8,7 @@
#include <util/prec.hpp>
#include <data/locale.hpp>
#include <data/localized_string.hpp>
#include <data/game.hpp>
#include <data/stylesheet.hpp>
#include <data/symbol_font.hpp>
@@ -118,3 +119,23 @@ String tr(const Package& pkg, const String& subcat, const String& key, DefaultLo
}
return loc->tr(subcat, key, def);
}
// ----------------------------------------------------------------------------- : LocalizedString
String const& LocalizedString::get(String const& locale) const {
auto it = translations.find(locale);
if (it != translations.end()) {
return it->second;
} else {
return default_;
}
}
String const& LocalizedString::get(Locale const& locale) const {
return get(locale.name());
}
String const& LocalizedString::get() const {
if (translations.empty()) return default_;
return get(the_locale->name());
}