30 if ( sep != boost::string_ref::npos )
50 ret =
IdString( std::string(language_r) +
"_" + country_r.
c_str() );
57 ret =
IdString(
"_" + std::string(country_r) );
81 std::string ret( lc.
_l.
name() );
93 static const IdString special(
"pt_BR" );
95 if ( index_r == special )
112 if ( sep != boost::string_ref::npos )
113 code_r = code_r.substr( 0, sep );
118 {
return code_r.find_first_of(
"@." ); }
131 typedef std::unordered_map<IdString,LC>
CodeMap;
145 CodeMap::value_type newval( index_r,
LC() );
147 boost::string_ref str( index_r.
c_str() );
149 if ( sep == boost::string_ref::npos )
154 std::string dup( str );
160 it =
_codeMap.insert( std::move(newval) ).first;
181 : _str( CodeMaps::withoutTrash( str_r ) )
185 : _str( CodeMaps::withoutTrash( str_r ) )
189 : _str( CodeMaps::withoutTrash( str_r ) )
193 : _str( CodeMaps::combineLC( language_r, country_r ) )
200 {
return CodeMaps::instance().language(
_str ); }
203 {
return CodeMaps::instance().country(
_str ); }
206 {
return CodeMaps::instance().name(
_str ); }
215 if ( ! avLocales_r.empty() )
219 for ( ; requested_r; requested_r = requested_r.
fallback() )
221 if ( avLocales_r.count( requested_r ) )
static const Locale noCode
Empty code.
LanguageCode language() const
The language part.
static IdString combineLC(LanguageCode language_r, CountryCode country_r)
Return IdString from language/country codes.
static ZConfig & instance()
Singleton ctor.
static const Locale enCode
Last resort "en".
static IdString withoutTrash(const char *code_r)
Return IdString without trailing garbage.
static const LanguageCode enCode
Last resort "en".
Locale()
Default Ctor: noCode.
std::unordered_map< IdString, LC > CodeMap
LanguageCode language(IdString index_r)
Locale fallback(IdString index_r)
Access to the sat-pools string space.
static boost::string_ref::size_type trashStart(IdString code_r)
std::string name() const
Return the translated language name; if unknown the language code.
static Locale bestMatch(const LocaleSet &avLocales_r, Locale requested_r=Locale())
Return the best match for Locale requested_r within the available avLocales_r.
static boost::string_ref::size_type trashStart(boost::string_ref code_r)
static const IdString Empty
Empty string.
Locale fallback() const
Return the fallback locale for this locale, if no fallback exists the empty Locale::noCode.
static CodeMaps & instance()
The singleton.
static IdString withoutTrash(IdString code_r)
Return IdString without trailing garbage.
CountryCode country() const
The county part.
const char * c_str() const
Conversion to const char *
std::string name() const
Return the translated locale name.
'Language[_Country]' codes.
const char * c_str() const
std::string name() const
Return the translated country name; if unknown the country code.
LC(LanguageCode l_r, CountryCode c_r)
CountryCode country(IdString index_r)
static IdString withoutTrash(const std::string &code_r)
Return IdString without trailing garbage.
static const IdString Null
No or Null string ( Id 0 ).
std::string name(IdString index_r)
CodeMaps()
Ctor initializes the code maps.
Locale textLocale() const
The locale for translated texts zypp uses.
static IdString withoutTrash(boost::string_ref code_r)
const LC & getIndex(IdString index_r)
Return LC for index_r, creating it if necessary.
std::unordered_set< Locale > LocaleSet
Language codes (iso639_2/iso639_1).
Country codes (iso3166-1-alpha-2).