Merge branch 'cldr-data'
This commit is contained in:
commit
d194670625
@ -21,11 +21,14 @@ set( libSources
|
||||
JobQueue.cpp
|
||||
ProcessJob.cpp
|
||||
Settings.cpp
|
||||
)
|
||||
set( partSources
|
||||
|
||||
# Locale-data service
|
||||
locale/Lookup.cpp
|
||||
|
||||
# Partition service
|
||||
partition/PartitionSize.cpp
|
||||
)
|
||||
set( utilsSources
|
||||
|
||||
# Utility service
|
||||
utils/CalamaresUtilsSystem.cpp
|
||||
utils/CommandList.cpp
|
||||
utils/Dirs.cpp
|
||||
@ -75,7 +78,7 @@ if( WITH_PYTHON )
|
||||
)
|
||||
endif()
|
||||
|
||||
add_library( calamares SHARED ${libSources} ${kdsagSources} ${partSources} ${utilsSources} )
|
||||
add_library( calamares SHARED ${libSources} ${kdsagSources} )
|
||||
set_target_properties( calamares
|
||||
PROPERTIES
|
||||
VERSION ${CALAMARES_VERSION_SHORT}
|
||||
|
235
src/libcalamares/locale/CountryData_p.cpp
Normal file
235
src/libcalamares/locale/CountryData_p.cpp
Normal file
@ -0,0 +1,235 @@
|
||||
/* GENERATED FILE DO NOT EDIT
|
||||
*
|
||||
* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* This file is derived from CLDR data from Unicode, Inc. Applicable terms:
|
||||
*
|
||||
* A. Unicode Copyright
|
||||
* 1. Copyright © 1991-2019 Unicode, Inc. All rights reserved.
|
||||
* B. Definitions
|
||||
* Unicode Data Files ("DATA FILES") include all data files under the directories:
|
||||
* https://www.unicode.org/Public/
|
||||
* C. Terms of Use
|
||||
* 2. Any person is hereby authorized, without fee, to view, use, reproduce,
|
||||
* and distribute all documents and files, subject to the Terms and
|
||||
* Conditions herein.
|
||||
*/
|
||||
|
||||
// BEGIN Generated from CLDR data
|
||||
|
||||
|
||||
struct CountryData
|
||||
{
|
||||
QLocale::Language l;
|
||||
QLocale::Country c;
|
||||
char cc1;
|
||||
char cc2;
|
||||
};
|
||||
|
||||
static constexpr int const country_data_size = 198;
|
||||
|
||||
static const CountryData country_data_table[] = {
|
||||
{ QLocale::Language::Catalan, QLocale::Country::Andorra, 'A', 'D' },
|
||||
{ QLocale::Language::Arabic, QLocale::Country::UnitedArabEmirates, 'A', 'E' },
|
||||
{ QLocale::Language::Persian, QLocale::Country::Afghanistan, 'A', 'F' },
|
||||
{ QLocale::Language::Albanian, QLocale::Country::Albania, 'A', 'L' },
|
||||
{ QLocale::Language::Armenian, QLocale::Country::Armenia, 'A', 'M' },
|
||||
{ QLocale::Language::Portuguese, QLocale::Country::Angola, 'A', 'O' },
|
||||
{ QLocale::Language::AnyLanguage, QLocale::Country::Antarctica, 'A', 'Q' },
|
||||
{ QLocale::Language::Spanish, QLocale::Country::Argentina, 'A', 'R' },
|
||||
{ QLocale::Language::Samoan, QLocale::Country::AmericanSamoa, 'A', 'S' },
|
||||
{ QLocale::Language::German, QLocale::Country::Austria, 'A', 'T' },
|
||||
{ QLocale::Language::Dutch, QLocale::Country::Aruba, 'A', 'W' },
|
||||
{ QLocale::Language::Swedish, QLocale::Country::AlandIslands, 'A', 'X' },
|
||||
{ QLocale::Language::Azerbaijani, QLocale::Country::Azerbaijan, 'A', 'Z' },
|
||||
{ QLocale::Language::Bosnian, QLocale::Country::BosniaAndHerzegowina, 'B', 'A' },
|
||||
{ QLocale::Language::Bengali, QLocale::Country::Bangladesh, 'B', 'D' },
|
||||
{ QLocale::Language::Dutch, QLocale::Country::Belgium, 'B', 'E' },
|
||||
{ QLocale::Language::French, QLocale::Country::BurkinaFaso, 'B', 'F' },
|
||||
{ QLocale::Language::Bulgarian, QLocale::Country::Bulgaria, 'B', 'G' },
|
||||
{ QLocale::Language::Arabic, QLocale::Country::Bahrain, 'B', 'H' },
|
||||
{ QLocale::Language::Rundi, QLocale::Country::Burundi, 'B', 'I' },
|
||||
{ QLocale::Language::French, QLocale::Country::Benin, 'B', 'J' },
|
||||
{ QLocale::Language::French, QLocale::Country::SaintBarthelemy, 'B', 'L' },
|
||||
{ QLocale::Language::Malay, QLocale::Country::Brunei, 'B', 'N' },
|
||||
{ QLocale::Language::Spanish, QLocale::Country::Bolivia, 'B', 'O' },
|
||||
{ QLocale::Language::Papiamento, QLocale::Country::Bonaire, 'B', 'Q' },
|
||||
{ QLocale::Language::Portuguese, QLocale::Country::Brazil, 'B', 'R' },
|
||||
{ QLocale::Language::Dzongkha, QLocale::Country::Bhutan, 'B', 'T' },
|
||||
{ QLocale::Language::AnyLanguage, QLocale::Country::BouvetIsland, 'B', 'V' },
|
||||
{ QLocale::Language::Belarusian, QLocale::Country::Belarus, 'B', 'Y' },
|
||||
{ QLocale::Language::Swahili, QLocale::Country::CongoKinshasa, 'C', 'D' },
|
||||
{ QLocale::Language::French, QLocale::Country::CentralAfricanRepublic, 'C', 'F' },
|
||||
{ QLocale::Language::French, QLocale::Country::CongoBrazzaville, 'C', 'G' },
|
||||
{ QLocale::Language::German, QLocale::Country::Switzerland, 'C', 'H' },
|
||||
{ QLocale::Language::French, QLocale::Country::IvoryCoast, 'C', 'I' },
|
||||
{ QLocale::Language::Spanish, QLocale::Country::Chile, 'C', 'L' },
|
||||
{ QLocale::Language::French, QLocale::Country::Cameroon, 'C', 'M' },
|
||||
{ QLocale::Language::Chinese, QLocale::Country::China, 'C', 'N' },
|
||||
{ QLocale::Language::Spanish, QLocale::Country::Colombia, 'C', 'O' },
|
||||
{ QLocale::Language::AnyLanguage, QLocale::Country::ClippertonIsland, 'C', 'P' },
|
||||
{ QLocale::Language::Spanish, QLocale::Country::CostaRica, 'C', 'R' },
|
||||
{ QLocale::Language::Spanish, QLocale::Country::Cuba, 'C', 'U' },
|
||||
{ QLocale::Language::Portuguese, QLocale::Country::CapeVerde, 'C', 'V' },
|
||||
{ QLocale::Language::Papiamento, QLocale::Country::CuraSao, 'C', 'W' },
|
||||
{ QLocale::Language::Greek, QLocale::Country::Cyprus, 'C', 'Y' },
|
||||
{ QLocale::Language::Czech, QLocale::Country::CzechRepublic, 'C', 'Z' },
|
||||
{ QLocale::Language::German, QLocale::Country::Germany, 'D', 'E' },
|
||||
{ QLocale::Language::Afar, QLocale::Country::Djibouti, 'D', 'J' },
|
||||
{ QLocale::Language::Danish, QLocale::Country::Denmark, 'D', 'K' },
|
||||
{ QLocale::Language::Spanish, QLocale::Country::DominicanRepublic, 'D', 'O' },
|
||||
{ QLocale::Language::Arabic, QLocale::Country::Algeria, 'D', 'Z' },
|
||||
{ QLocale::Language::Spanish, QLocale::Country::CeutaAndMelilla, 'E', 'A' },
|
||||
{ QLocale::Language::Spanish, QLocale::Country::Ecuador, 'E', 'C' },
|
||||
{ QLocale::Language::Estonian, QLocale::Country::Estonia, 'E', 'E' },
|
||||
{ QLocale::Language::Arabic, QLocale::Country::Egypt, 'E', 'G' },
|
||||
{ QLocale::Language::Arabic, QLocale::Country::WesternSahara, 'E', 'H' },
|
||||
{ QLocale::Language::Tigrinya, QLocale::Country::Eritrea, 'E', 'R' },
|
||||
{ QLocale::Language::Spanish, QLocale::Country::Spain, 'E', 'S' },
|
||||
{ QLocale::Language::Amharic, QLocale::Country::Ethiopia, 'E', 'T' },
|
||||
{ QLocale::Language::English, QLocale::Country::EuropeanUnion, 'E', 'U' },
|
||||
{ QLocale::Language::German, QLocale::Country::AnyCountry, 'E', 'Z' },
|
||||
{ QLocale::Language::Finnish, QLocale::Country::Finland, 'F', 'I' },
|
||||
{ QLocale::Language::Faroese, QLocale::Country::FaroeIslands, 'F', 'O' },
|
||||
{ QLocale::Language::French, QLocale::Country::France, 'F', 'R' },
|
||||
{ QLocale::Language::French, QLocale::Country::Gabon, 'G', 'A' },
|
||||
{ QLocale::Language::Georgian, QLocale::Country::Georgia, 'G', 'E' },
|
||||
{ QLocale::Language::French, QLocale::Country::FrenchGuiana, 'G', 'F' },
|
||||
{ QLocale::Language::Akan, QLocale::Country::Ghana, 'G', 'H' },
|
||||
{ QLocale::Language::Greenlandic, QLocale::Country::Greenland, 'G', 'L' },
|
||||
{ QLocale::Language::French, QLocale::Country::Guinea, 'G', 'N' },
|
||||
{ QLocale::Language::French, QLocale::Country::Guadeloupe, 'G', 'P' },
|
||||
{ QLocale::Language::Spanish, QLocale::Country::EquatorialGuinea, 'G', 'Q' },
|
||||
{ QLocale::Language::Greek, QLocale::Country::Greece, 'G', 'R' },
|
||||
{ QLocale::Language::AnyLanguage, QLocale::Country::SouthGeorgiaAndTheSouthSandwichIslands, 'G', 'S' },
|
||||
{ QLocale::Language::Spanish, QLocale::Country::Guatemala, 'G', 'T' },
|
||||
{ QLocale::Language::Portuguese, QLocale::Country::GuineaBissau, 'G', 'W' },
|
||||
{ QLocale::Language::Chinese, QLocale::Country::HongKong, 'H', 'K' },
|
||||
{ QLocale::Language::AnyLanguage, QLocale::Country::HeardAndMcDonaldIslands, 'H', 'M' },
|
||||
{ QLocale::Language::Spanish, QLocale::Country::Honduras, 'H', 'N' },
|
||||
{ QLocale::Language::Croatian, QLocale::Country::Croatia, 'H', 'R' },
|
||||
{ QLocale::Language::Haitian, QLocale::Country::Haiti, 'H', 'T' },
|
||||
{ QLocale::Language::Hungarian, QLocale::Country::Hungary, 'H', 'U' },
|
||||
{ QLocale::Language::Spanish, QLocale::Country::CanaryIslands, 'I', 'C' },
|
||||
{ QLocale::Language::Indonesian, QLocale::Country::Indonesia, 'I', 'D' },
|
||||
{ QLocale::Language::Hebrew, QLocale::Country::Israel, 'I', 'L' },
|
||||
{ QLocale::Language::Hindi, QLocale::Country::India, 'I', 'N' },
|
||||
{ QLocale::Language::Arabic, QLocale::Country::Iraq, 'I', 'Q' },
|
||||
{ QLocale::Language::Persian, QLocale::Country::Iran, 'I', 'R' },
|
||||
{ QLocale::Language::Icelandic, QLocale::Country::Iceland, 'I', 'S' },
|
||||
{ QLocale::Language::Italian, QLocale::Country::Italy, 'I', 'T' },
|
||||
{ QLocale::Language::Arabic, QLocale::Country::Jordan, 'J', 'O' },
|
||||
{ QLocale::Language::Japanese, QLocale::Country::Japan, 'J', 'P' },
|
||||
{ QLocale::Language::Swahili, QLocale::Country::Kenya, 'K', 'E' },
|
||||
{ QLocale::Language::Kirghiz, QLocale::Country::Kyrgyzstan, 'K', 'G' },
|
||||
{ QLocale::Language::Khmer, QLocale::Country::Cambodia, 'K', 'H' },
|
||||
{ QLocale::Language::Arabic, QLocale::Country::Comoros, 'K', 'M' },
|
||||
{ QLocale::Language::Korean, QLocale::Country::NorthKorea, 'K', 'P' },
|
||||
{ QLocale::Language::Korean, QLocale::Country::SouthKorea, 'K', 'R' },
|
||||
{ QLocale::Language::Arabic, QLocale::Country::Kuwait, 'K', 'W' },
|
||||
{ QLocale::Language::Russian, QLocale::Country::Kazakhstan, 'K', 'Z' },
|
||||
{ QLocale::Language::Lao, QLocale::Country::Laos, 'L', 'A' },
|
||||
{ QLocale::Language::Arabic, QLocale::Country::Lebanon, 'L', 'B' },
|
||||
{ QLocale::Language::German, QLocale::Country::Liechtenstein, 'L', 'I' },
|
||||
{ QLocale::Language::Sinhala, QLocale::Country::SriLanka, 'L', 'K' },
|
||||
{ QLocale::Language::SouthernSotho, QLocale::Country::Lesotho, 'L', 'S' },
|
||||
{ QLocale::Language::Lithuanian, QLocale::Country::Lithuania, 'L', 'T' },
|
||||
{ QLocale::Language::French, QLocale::Country::Luxembourg, 'L', 'U' },
|
||||
{ QLocale::Language::Latvian, QLocale::Country::Latvia, 'L', 'V' },
|
||||
{ QLocale::Language::Arabic, QLocale::Country::Libya, 'L', 'Y' },
|
||||
{ QLocale::Language::Arabic, QLocale::Country::Morocco, 'M', 'A' },
|
||||
{ QLocale::Language::French, QLocale::Country::Monaco, 'M', 'C' },
|
||||
{ QLocale::Language::Romanian, QLocale::Country::Moldova, 'M', 'D' },
|
||||
{ QLocale::Language::Serbian, QLocale::Country::Montenegro, 'M', 'E' },
|
||||
{ QLocale::Language::French, QLocale::Country::SaintMartin, 'M', 'F' },
|
||||
{ QLocale::Language::Malagasy, QLocale::Country::Madagascar, 'M', 'G' },
|
||||
{ QLocale::Language::Macedonian, QLocale::Country::Macedonia, 'M', 'K' },
|
||||
{ QLocale::Language::Bambara, QLocale::Country::Mali, 'M', 'L' },
|
||||
{ QLocale::Language::Burmese, QLocale::Country::Myanmar, 'M', 'M' },
|
||||
{ QLocale::Language::Mongolian, QLocale::Country::Mongolia, 'M', 'N' },
|
||||
{ QLocale::Language::Chinese, QLocale::Country::Macau, 'M', 'O' },
|
||||
{ QLocale::Language::French, QLocale::Country::Martinique, 'M', 'Q' },
|
||||
{ QLocale::Language::Arabic, QLocale::Country::Mauritania, 'M', 'R' },
|
||||
{ QLocale::Language::Maltese, QLocale::Country::Malta, 'M', 'T' },
|
||||
{ QLocale::Language::Morisyen, QLocale::Country::Mauritius, 'M', 'U' },
|
||||
{ QLocale::Language::Divehi, QLocale::Country::Maldives, 'M', 'V' },
|
||||
{ QLocale::Language::Spanish, QLocale::Country::Mexico, 'M', 'X' },
|
||||
{ QLocale::Language::Malay, QLocale::Country::Malaysia, 'M', 'Y' },
|
||||
{ QLocale::Language::Portuguese, QLocale::Country::Mozambique, 'M', 'Z' },
|
||||
{ QLocale::Language::Afrikaans, QLocale::Country::Namibia, 'N', 'A' },
|
||||
{ QLocale::Language::French, QLocale::Country::NewCaledonia, 'N', 'C' },
|
||||
{ QLocale::Language::Hausa, QLocale::Country::Niger, 'N', 'E' },
|
||||
{ QLocale::Language::Spanish, QLocale::Country::Nicaragua, 'N', 'I' },
|
||||
{ QLocale::Language::Dutch, QLocale::Country::Netherlands, 'N', 'L' },
|
||||
{ QLocale::Language::NorwegianBokmal, QLocale::Country::Norway, 'N', 'O' },
|
||||
{ QLocale::Language::Nepali, QLocale::Country::Nepal, 'N', 'P' },
|
||||
{ QLocale::Language::Arabic, QLocale::Country::Oman, 'O', 'M' },
|
||||
{ QLocale::Language::Spanish, QLocale::Country::Panama, 'P', 'A' },
|
||||
{ QLocale::Language::Spanish, QLocale::Country::Peru, 'P', 'E' },
|
||||
{ QLocale::Language::French, QLocale::Country::FrenchPolynesia, 'P', 'F' },
|
||||
{ QLocale::Language::TokPisin, QLocale::Country::PapuaNewGuinea, 'P', 'G' },
|
||||
{ QLocale::Language::Filipino, QLocale::Country::Philippines, 'P', 'H' },
|
||||
{ QLocale::Language::Urdu, QLocale::Country::Pakistan, 'P', 'K' },
|
||||
{ QLocale::Language::Polish, QLocale::Country::Poland, 'P', 'L' },
|
||||
{ QLocale::Language::French, QLocale::Country::SaintPierreAndMiquelon, 'P', 'M' },
|
||||
{ QLocale::Language::Spanish, QLocale::Country::PuertoRico, 'P', 'R' },
|
||||
{ QLocale::Language::Arabic, QLocale::Country::PalestinianTerritories, 'P', 'S' },
|
||||
{ QLocale::Language::Portuguese, QLocale::Country::Portugal, 'P', 'T' },
|
||||
{ QLocale::Language::Palauan, QLocale::Country::Palau, 'P', 'W' },
|
||||
{ QLocale::Language::Guarani, QLocale::Country::Paraguay, 'P', 'Y' },
|
||||
{ QLocale::Language::Arabic, QLocale::Country::Qatar, 'Q', 'A' },
|
||||
{ QLocale::Language::English, QLocale::Country::OutlyingOceania, 'Q', 'O' },
|
||||
{ QLocale::Language::French, QLocale::Country::Reunion, 'R', 'E' },
|
||||
{ QLocale::Language::Romanian, QLocale::Country::Romania, 'R', 'O' },
|
||||
{ QLocale::Language::Serbian, QLocale::Country::Serbia, 'R', 'S' },
|
||||
{ QLocale::Language::Russian, QLocale::Country::Russia, 'R', 'U' },
|
||||
{ QLocale::Language::Kinyarwanda, QLocale::Country::Rwanda, 'R', 'W' },
|
||||
{ QLocale::Language::Arabic, QLocale::Country::SaudiArabia, 'S', 'A' },
|
||||
{ QLocale::Language::French, QLocale::Country::Seychelles, 'S', 'C' },
|
||||
{ QLocale::Language::Arabic, QLocale::Country::Sudan, 'S', 'D' },
|
||||
{ QLocale::Language::Swedish, QLocale::Country::Sweden, 'S', 'E' },
|
||||
{ QLocale::Language::Slovenian, QLocale::Country::Slovenia, 'S', 'I' },
|
||||
{ QLocale::Language::NorwegianBokmal, QLocale::Country::SvalbardAndJanMayenIslands, 'S', 'J' },
|
||||
{ QLocale::Language::Slovak, QLocale::Country::Slovakia, 'S', 'K' },
|
||||
{ QLocale::Language::Italian, QLocale::Country::SanMarino, 'S', 'M' },
|
||||
{ QLocale::Language::French, QLocale::Country::Senegal, 'S', 'N' },
|
||||
{ QLocale::Language::Somali, QLocale::Country::Somalia, 'S', 'O' },
|
||||
{ QLocale::Language::Dutch, QLocale::Country::Suriname, 'S', 'R' },
|
||||
{ QLocale::Language::Portuguese, QLocale::Country::SaoTomeAndPrincipe, 'S', 'T' },
|
||||
{ QLocale::Language::Spanish, QLocale::Country::ElSalvador, 'S', 'V' },
|
||||
{ QLocale::Language::Arabic, QLocale::Country::Syria, 'S', 'Y' },
|
||||
{ QLocale::Language::French, QLocale::Country::Chad, 'T', 'D' },
|
||||
{ QLocale::Language::French, QLocale::Country::FrenchSouthernTerritories, 'T', 'F' },
|
||||
{ QLocale::Language::French, QLocale::Country::Togo, 'T', 'G' },
|
||||
{ QLocale::Language::Thai, QLocale::Country::Thailand, 'T', 'H' },
|
||||
{ QLocale::Language::Tajik, QLocale::Country::Tajikistan, 'T', 'J' },
|
||||
{ QLocale::Language::TokelauLanguage, QLocale::Country::Tokelau, 'T', 'K' },
|
||||
{ QLocale::Language::Portuguese, QLocale::Country::EastTimor, 'T', 'L' },
|
||||
{ QLocale::Language::Turkmen, QLocale::Country::Turkmenistan, 'T', 'M' },
|
||||
{ QLocale::Language::Arabic, QLocale::Country::Tunisia, 'T', 'N' },
|
||||
{ QLocale::Language::Tongan, QLocale::Country::Tonga, 'T', 'O' },
|
||||
{ QLocale::Language::Turkish, QLocale::Country::Turkey, 'T', 'R' },
|
||||
{ QLocale::Language::TuvaluLanguage, QLocale::Country::Tuvalu, 'T', 'V' },
|
||||
{ QLocale::Language::Chinese, QLocale::Country::Taiwan, 'T', 'W' },
|
||||
{ QLocale::Language::Swahili, QLocale::Country::Tanzania, 'T', 'Z' },
|
||||
{ QLocale::Language::Ukrainian, QLocale::Country::Ukraine, 'U', 'A' },
|
||||
{ QLocale::Language::Swahili, QLocale::Country::Uganda, 'U', 'G' },
|
||||
{ QLocale::Language::Spanish, QLocale::Country::Uruguay, 'U', 'Y' },
|
||||
{ QLocale::Language::Uzbek, QLocale::Country::Uzbekistan, 'U', 'Z' },
|
||||
{ QLocale::Language::Italian, QLocale::Country::VaticanCityState, 'V', 'A' },
|
||||
{ QLocale::Language::Spanish, QLocale::Country::Venezuela, 'V', 'E' },
|
||||
{ QLocale::Language::Vietnamese, QLocale::Country::Vietnam, 'V', 'N' },
|
||||
{ QLocale::Language::Bislama, QLocale::Country::Vanuatu, 'V', 'U' },
|
||||
{ QLocale::Language::French, QLocale::Country::WallisAndFutunaIslands, 'W', 'F' },
|
||||
{ QLocale::Language::Samoan, QLocale::Country::Samoa, 'W', 'S' },
|
||||
{ QLocale::Language::Albanian, QLocale::Country::Kosovo, 'X', 'K' },
|
||||
{ QLocale::Language::Arabic, QLocale::Country::Yemen, 'Y', 'E' },
|
||||
{ QLocale::Language::French, QLocale::Country::Mayotte, 'Y', 'T' },
|
||||
{ QLocale::Language::Shona, QLocale::Country::Zimbabwe, 'Z', 'W' },
|
||||
{ QLocale::Language::AnyLanguage, QLocale::Country::AnyCountry, 0, 0 },
|
||||
};
|
||||
|
||||
static_assert( (sizeof(country_data_table) / sizeof(CountryData)) == country_data_size, "Table size mismatch for CountryData" );
|
||||
|
||||
|
||||
// END Generated from CLDR data
|
90
src/libcalamares/locale/Lookup.cpp
Normal file
90
src/libcalamares/locale/Lookup.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Calamares is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Lookup.h"
|
||||
|
||||
#include "CountryData_p.cpp"
|
||||
|
||||
namespace Calamares
|
||||
{
|
||||
|
||||
struct TwoChar
|
||||
{
|
||||
TwoChar( const QString& code )
|
||||
: cc1(0)
|
||||
, cc2(0)
|
||||
{
|
||||
if ( code.length() == 2 )
|
||||
{
|
||||
cc1 = code[0].toLatin1();
|
||||
cc2 = code[1].toLatin1();
|
||||
}
|
||||
}
|
||||
|
||||
char cc1;
|
||||
char cc2;
|
||||
};
|
||||
|
||||
static const CountryData* lookup( TwoChar c )
|
||||
{
|
||||
if ( !c.cc1 )
|
||||
return nullptr;
|
||||
|
||||
const CountryData* p = std::find_if(country_data_table, country_data_table + country_data_size,
|
||||
[c=c]( const CountryData& d ){ return (d.cc1 == c.cc1) && (d.cc2 == c.cc2); }
|
||||
);
|
||||
if ( p == country_data_table + country_data_size )
|
||||
return nullptr;
|
||||
return p;
|
||||
}
|
||||
|
||||
QLocale::Country countryForCode(const QString& code)
|
||||
{
|
||||
const CountryData* p = lookup( TwoChar( code ) );
|
||||
return p ? p->c : QLocale::Country::AnyCountry;
|
||||
}
|
||||
|
||||
QLocale::Language languageForCountry(const QString& code)
|
||||
{
|
||||
const CountryData* p = lookup( TwoChar( code ) );
|
||||
return p ? p->l : QLocale::Language::AnyLanguage;
|
||||
}
|
||||
|
||||
QPair<QLocale::Country, QLocale::Language> countryData(const QString& code)
|
||||
{
|
||||
const CountryData* p = lookup( TwoChar( code ) );
|
||||
return p ? qMakePair( p->c, p->l ) : qMakePair( QLocale::Country::AnyCountry, QLocale::Language::AnyLanguage );
|
||||
}
|
||||
|
||||
QLocale countryLocale(const QString& code)
|
||||
{
|
||||
auto p = countryData( code );
|
||||
return QLocale( p.second, p.first );
|
||||
}
|
||||
|
||||
QLocale::Language languageForCountry(QLocale::Country country)
|
||||
{
|
||||
const CountryData* p = std::find_if(country_data_table, country_data_table + country_data_size,
|
||||
[c=country]( const CountryData& d ){ return d.c == c; }
|
||||
);
|
||||
if ( p == country_data_table + country_data_size )
|
||||
return QLocale::Language::AnyLanguage;
|
||||
return p->l;
|
||||
}
|
||||
|
||||
} // namespace
|
52
src/libcalamares/locale/Lookup.h
Normal file
52
src/libcalamares/locale/Lookup.h
Normal file
@ -0,0 +1,52 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Calamares is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LOCALE_LOOKUP_H
|
||||
#define LOCALE_LOOKUP_H
|
||||
|
||||
#include "DllMacro.h"
|
||||
|
||||
#include <QLocale>
|
||||
#include <QPair>
|
||||
|
||||
namespace Calamares
|
||||
{
|
||||
/* All the functions in this file do lookups of locale data
|
||||
* based on CLDR tables; these are lookups that you can't (easily)
|
||||
* do with just QLocale (e.g. from 2-letter country code to a likely
|
||||
* locale).
|
||||
*/
|
||||
|
||||
/// @brief Map a 2-letter code to a Country, or AnyCountry if not found
|
||||
DLLEXPORT QLocale::Country countryForCode( const QString& code );
|
||||
/** @brief Map a Country to a Language, or AnyLanguage if not found
|
||||
*
|
||||
* This is a *likely* language for the given country, based on the
|
||||
* CLDR tables. For instance, this maps Belgium to Dutch.
|
||||
*/
|
||||
DLLEXPORT QLocale::Language languageForCountry( QLocale::Country country );
|
||||
/// @brief Map a 2-letter code to a Language, or AnyLanguage if not found
|
||||
DLLEXPORT QLocale::Language languageForCountry( const QString& code );
|
||||
|
||||
/// @brief Get both Country and Language for a 2-letter code
|
||||
DLLEXPORT QPair< QLocale::Country, QLocale::Language > countryData( const QString& code );
|
||||
/// @brief Get a likely locale for a 2-letter country code
|
||||
DLLEXPORT QLocale countryLocale( const QString& code );
|
||||
} // namespace
|
||||
|
||||
#endif
|
287
src/libcalamares/locale/cldr-extractor.py
Normal file
287
src/libcalamares/locale/cldr-extractor.py
Normal file
@ -0,0 +1,287 @@
|
||||
#! /usr/bin/env python3
|
||||
#
|
||||
# === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
#
|
||||
# Python3 script to scrape some data out of ICU CLDR supplemental data.
|
||||
#
|
||||
### BEGIN LICENSES
|
||||
#
|
||||
# Copyright 2019 Adriaan de Groot <groot@kde.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
### END LICENSES
|
||||
|
||||
### BEGIN USAGE
|
||||
#
|
||||
"""
|
||||
Python3 script to scrape some data out of ICU CLDR supplemental data.
|
||||
|
||||
To use this script, you must have downloaded the CLDR data, e.g.
|
||||
http://unicode.org/Public/cldr/35.1/, and extracted the zip file.
|
||||
Run the script from **inside** the common/ durectory that is created
|
||||
(or fix the hard-coded path).
|
||||
|
||||
The script tries to print C++ code that compiles; if there are encoding
|
||||
problems, it will print some kind of representation of the problematic
|
||||
lines.
|
||||
|
||||
To avoid having to cross-reference multiple XML files, the script
|
||||
cheats: it reads the comments as well to get names. So it looks for
|
||||
pairs of lines like this:
|
||||
|
||||
<likelySubtag from="und_BQ" to="pap_Latn_BQ"/>
|
||||
<!--{ ?; ?; Caribbean Netherlands } => { Papiamento; Latin; Caribbean Netherlands }-->
|
||||
|
||||
It extracts the 2-character country code "BQ" from the sub-tag, and
|
||||
parses the comment to get a language and country name (instead of looking up
|
||||
"pap" and "BQ" in other tables). This may be considered a hack.
|
||||
|
||||
A large collection of exceptions can be found in the two *_mapper tables,
|
||||
which massage the CLDR names to Qt enum values.
|
||||
"""
|
||||
#
|
||||
### END USAGE
|
||||
|
||||
import sys
|
||||
|
||||
# These are languages listed in CLDR that don't match
|
||||
# the enum-values in QLocale::Language.
|
||||
language_mapper = {
|
||||
"?" : "AnyLanguage",
|
||||
"Bangla" : "Bengali",
|
||||
"Kalaallisut" : "Greenlandic",
|
||||
"Haitian Creole" : "Haitian",
|
||||
"Kyrgyz" : "Kirghiz",
|
||||
"Norwegian Bokmål" : "NorwegianBokmal",
|
||||
"Tokelau" : "TokelauLanguage",
|
||||
"Tuvalu" : "TuvaluLanguage",
|
||||
}
|
||||
|
||||
country_mapper = {
|
||||
"Åland Islands" : "AlandIslands",
|
||||
"St. Barthélemy" : "SaintBarthelemy",
|
||||
"Côte d’Ivoire" : "IvoryCoast",
|
||||
"Curaçao" : "CuraSao",
|
||||
"Réunion" : "Reunion",
|
||||
"São Tomé & Príncipe" : "SaoTomeAndPrincipe",
|
||||
"Bosnia & Herzegovina" : "BosniaAndHerzegowina",
|
||||
"Czechia" : "CzechRepublic",
|
||||
"St. Pierre & Miquelon" : "SaintPierreAndMiquelon",
|
||||
"Vatican City" : "VaticanCityState",
|
||||
"South Georgia & South Sandwich Islands" : "SouthGeorgiaAndTheSouthSandwichIslands",
|
||||
"Timor-Leste" : "EastTimor",
|
||||
"Wallis & Futuna" : "WallisAndFutunaIslands",
|
||||
"Myanmar (Burma)" : "Myanmar",
|
||||
"Svalbard & Jan Mayen" : "SvalbardAndJanMayenIslands",
|
||||
"St. Martin" : "SaintMartin",
|
||||
"North Macedonia" : "Macedonia",
|
||||
"Hong Kong SAR China" : "HongKong",
|
||||
"Macao SAR China" : "Macau",
|
||||
"Eurozone" : "AnyCountry", # Not likely for GeoIP
|
||||
"Caribbean Netherlands" : "Bonaire", # Bonaire, Saba, St.Eustatius
|
||||
}
|
||||
|
||||
class CountryData:
|
||||
def __init__(self, country_code, language_name, country_name):
|
||||
"""
|
||||
Takes a 2-letter country name, and enum names from
|
||||
QLocale::Language and QLocale::Country. An empty
|
||||
@p country code is acceptable, for the terminating
|
||||
entry in the data array (and yields a 0,0 code).
|
||||
"""
|
||||
if country_code:
|
||||
assert len(country_code) == 2
|
||||
self.country_code = country_code
|
||||
self.language_enum = language_name
|
||||
self.country_enum = country_name
|
||||
else:
|
||||
self.country_code = ""
|
||||
self.language_enum = "AnyLanguage"
|
||||
self.country_enum = "AnyCountry"
|
||||
|
||||
def __str__(self):
|
||||
if self.country_code:
|
||||
char0 = "'{!s}'".format(self.country_code[0])
|
||||
char1 = "'{!s}'".format(self.country_code[1])
|
||||
else:
|
||||
char0 = "0"
|
||||
char1 = "0"
|
||||
|
||||
return "{!s} QLocale::Language::{!s}, QLocale::Country::{!s}, {!s}, {!s} {!s},".format(
|
||||
"{",
|
||||
self.language_enum,
|
||||
self.country_enum,
|
||||
char0,
|
||||
char1,
|
||||
"}")
|
||||
|
||||
# Must match type name below
|
||||
cpp_classname = "CountryData"
|
||||
|
||||
# Must match the output format of __str__ above
|
||||
cpp_declaration = """
|
||||
struct CountryData
|
||||
{
|
||||
QLocale::Language l;
|
||||
QLocale::Country c;
|
||||
char cc1;
|
||||
char cc2;
|
||||
};
|
||||
"""
|
||||
|
||||
|
||||
def extricate_subtags(l1, l2):
|
||||
"""
|
||||
Given two lines @p l1 and @p l2 which are the <likelySubtag> element-line
|
||||
and the comment-line underneath it, return a CountryData for them,
|
||||
or None if the two lines are not relevant (e.g. not the right subtag from,
|
||||
or 3-letter country codes.
|
||||
"""
|
||||
if 'from="und_' not in l1:
|
||||
return
|
||||
if '{ ?; ?;' not in l2:
|
||||
return
|
||||
|
||||
# This is extremely crude "parsing" which chops up the string
|
||||
# by delimiter and then extracts some substring.
|
||||
l1_parts = l1.split("und_")
|
||||
l2_parts = l2.split(";")
|
||||
|
||||
l1_first_quote = l1_parts[1].find('"')
|
||||
l1_code = l1_parts[1][:l1_first_quote]
|
||||
if len(l1_code) != 2:
|
||||
return
|
||||
|
||||
l2_brace = l2_parts[2].find("{")
|
||||
l2_language = l2_parts[2][l2_brace+1:].strip()
|
||||
l2_brace = l2_parts[2].find("}")
|
||||
l2_country = l2_parts[2][:l2_brace-1].strip()
|
||||
|
||||
# Handle mapped cases
|
||||
l2_language = language_mapper.get(l2_language, l2_language)
|
||||
l2_language = l2_language.replace(" ", "")
|
||||
|
||||
# Handle mapped cases and then do a bunch of standard replacements.
|
||||
l2_country = country_mapper.get(l2_country, l2_country)
|
||||
l2_country = l2_country.replace(" ", "").replace("-", "").replace(".","").replace("&","And")
|
||||
|
||||
return CountryData(l1_code, l2_language, l2_country)
|
||||
|
||||
|
||||
def read_subtags_file():
|
||||
"""
|
||||
Returns a list of CountryData objects from the likelySubtags file.
|
||||
"""
|
||||
data = []
|
||||
|
||||
with open("supplemental/likelySubtags.xml", "rt", encoding="UTF-8") as f:
|
||||
l1 = "a line"
|
||||
while l1:
|
||||
l1 = f.readline()
|
||||
if '<likelySubtag from="und_' not in l1:
|
||||
continue
|
||||
l2 = f.readline()
|
||||
|
||||
if l1:
|
||||
assert "likelySubtag" in l1, l1;
|
||||
assert "<!--" in l2, l2;
|
||||
|
||||
data.append(extricate_subtags(l1, l2))
|
||||
|
||||
data.append(CountryData("", None, None))
|
||||
return [c for c in data if c is not None]
|
||||
|
||||
|
||||
cpp_header_comment = """/* GENERATED FILE DO NOT EDIT
|
||||
*
|
||||
* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* This file is derived from CLDR data from Unicode, Inc. Applicable terms:
|
||||
*
|
||||
* A. Unicode Copyright
|
||||
* 1. Copyright © 1991-2019 Unicode, Inc. All rights reserved.
|
||||
* B. Definitions
|
||||
* Unicode Data Files ("DATA FILES") include all data files under the directories:
|
||||
* https://www.unicode.org/Public/
|
||||
* C. Terms of Use
|
||||
* 2. Any person is hereby authorized, without fee, to view, use, reproduce,
|
||||
* and distribute all documents and files, subject to the Terms and
|
||||
* Conditions herein.
|
||||
*/
|
||||
|
||||
// BEGIN Generated from CLDR data
|
||||
|
||||
"""
|
||||
|
||||
cpp_footer_comment = """
|
||||
// END Generated from CLDR data
|
||||
"""
|
||||
|
||||
|
||||
def make_identifier(classname):
|
||||
"""
|
||||
Given a class name (e.g. CountryData) return an identifer
|
||||
for the data-table for that class.
|
||||
"""
|
||||
identifier = [ classname[0].lower() ]
|
||||
for c in classname[1:]:
|
||||
if c.isupper():
|
||||
identifier.extend(["_", c.lower()])
|
||||
else:
|
||||
identifier.append(c)
|
||||
|
||||
return "".join(identifier)
|
||||
|
||||
|
||||
def export_class(cls, data):
|
||||
"""
|
||||
Given a @p cls and a list of @p data objects from that class,
|
||||
print (to stdout) a C++ file for that data.
|
||||
"""
|
||||
identifier = make_identifier(cls.cpp_classname)
|
||||
|
||||
with open("{!s}_p.cpp".format(cls.cpp_classname), "wt", encoding="UTF-8") as f:
|
||||
f.write(cpp_header_comment)
|
||||
f.write(cls.cpp_declaration)
|
||||
f.write("\nstatic constexpr int const {!s}_size = {!s};\n".format(
|
||||
identifier,
|
||||
len(data)))
|
||||
f.write("\nstatic const {!s} {!s}_table[] = {!s}\n".format(
|
||||
cls.cpp_classname,
|
||||
identifier,
|
||||
"{"))
|
||||
for d in data:
|
||||
f.write(str(d))
|
||||
f.write("\n")
|
||||
f.write("};\n\n");
|
||||
f.write("static_assert( (sizeof({!s}_table) / sizeof({!s})) == {!s}_size, \"Table size mismatch for {!s}\" );\n\n".format(
|
||||
identifier,
|
||||
cls.cpp_classname,
|
||||
identifier,
|
||||
cls.cpp_classname))
|
||||
f.write(cpp_footer_comment)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
export_class(CountryData, read_subtags_file())
|
Loading…
Reference in New Issue
Block a user