[coding][editor] Support alt_name and old_name in editor.

This commit is contained in:
tatiana-yan 2020-06-11 16:29:46 +03:00 committed by mpimenov
parent 34de7ac653
commit 714114922b
4 changed files with 31 additions and 1 deletions

View file

@ -104,6 +104,9 @@ StringUtf8Multilang::Languages const & StringUtf8Multilang::GetSupportedLanguage
// Asserts for generic class constants.
ASSERT_EQUAL(kLanguages[kDefaultCode].m_code, string("default"), ());
ASSERT_EQUAL(kLanguages[kInternationalCode].m_code, string("int_name"), ());
ASSERT_EQUAL(kLanguages[kAltNameCode].m_code, string("alt_name"), ());
ASSERT_EQUAL(kLanguages[kOldNameCode].m_code, string("old_name"), ());
ASSERT_EQUAL(kLanguages[kEnglishCode].m_code, string("en"), ());
static StringUtf8Multilang::Languages languages;
if (languages.empty())
{

View file

@ -86,6 +86,8 @@ public:
static int8_t constexpr kDefaultCode = 0;
static int8_t constexpr kEnglishCode = 1;
static int8_t constexpr kInternationalCode = 7;
static int8_t constexpr kAltNameCode = 53;
static int8_t constexpr kOldNameCode = 55;
/// How many languages we support on indexing stage. See full list in cpp file.
/// TODO(AlexZ): Review and replace invalid languages by valid ones.
static int8_t constexpr kMaxSupportedLanguages = 64;

View file

@ -92,6 +92,13 @@ char const * const XMLFeature::kDefaultLang =
StringUtf8Multilang::GetLangByCode(StringUtf8Multilang::kDefaultCode);
char const * const XMLFeature::kIntlLang =
StringUtf8Multilang::GetLangByCode(StringUtf8Multilang::kInternationalCode);
char const * const XMLFeature::kAltLang =
StringUtf8Multilang::GetLangByCode(StringUtf8Multilang::kAltNameCode);
char const * const XMLFeature::kOldLang =
StringUtf8Multilang::GetLangByCode(StringUtf8Multilang::kOldNameCode);
char const * const XMLFeature::kIntlName = XMLFeature::kIntlLang;
char const * const XMLFeature::kAltName = XMLFeature::kAltLang;
char const * const XMLFeature::kOldName = XMLFeature::kOldLang;
XMLFeature::XMLFeature(Type const type)
{
@ -239,6 +246,10 @@ string XMLFeature::GetName(string const & lang) const
{
if (lang == kIntlLang)
return GetTagValue(kIntlName);
if (lang == kAltLang)
return GetTagValue(kAltName);
if (lang == kOldLang)
return GetTagValue(kOldName);
auto const suffix = (lang == kDefaultLang || lang.empty()) ? "" : ":" + lang;
return GetTagValue(kDefaultName + suffix);
}
@ -253,7 +264,17 @@ void XMLFeature::SetName(string const & name) { SetName(kDefaultLang, name); }
void XMLFeature::SetName(string const & lang, string const & name)
{
if (lang == kIntlLang)
{
SetTagValue(kIntlName, name);
}
else if (lang == kAltLang)
{
SetTagValue(kAltName, name);
}
else if (lang == kOldLang)
{
SetTagValue(kOldName, name);
}
else
{
auto const suffix = (lang == kDefaultLang || lang.empty()) ? "" : ":" + lang;

View file

@ -31,10 +31,14 @@ DECLARE_EXCEPTION(NoHeader, XMLFeatureError);
class XMLFeature
{
static constexpr char const * kDefaultName = "name";
static constexpr char const * kIntlName = "int_name";
static constexpr char const * kLocalName = "name:";
static char const * const kIntlName;
static char const * const kAltName;
static char const * const kOldName;
static char const * const kDefaultLang;
static char const * const kIntlLang;
static char const * const kAltLang;
static char const * const kOldLang;
public:
// Used in point to string serialization.