Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Calamares
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
osak
Calamares
Commits
6cbf2d7e
Commit
6cbf2d7e
authored
2 years ago
by
Adriaan de Groot
Browse files
Options
Downloads
Patches
Plain Diff
[locale] Factor out the guess-language part
parent
40527ffd
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/modules/locale/LocaleConfiguration.cpp
+21
-23
21 additions, 23 deletions
src/modules/locale/LocaleConfiguration.cpp
with
21 additions
and
23 deletions
src/modules/locale/LocaleConfiguration.cpp
+
21
−
23
View file @
6cbf2d7e
...
@@ -42,16 +42,14 @@ LocaleConfiguration::setLanguage( const QString& localeName )
...
@@ -42,16 +42,14 @@ LocaleConfiguration::setLanguage( const QString& localeName )
m_lang
=
localeName
;
m_lang
=
localeName
;
}
}
/** @brief Returns the QString from @p availableLocales that best-matches.
LocaleConfiguration
*/
LocaleConfiguration
::
fromLanguageAndLocation
(
const
QString
&
languageLocale
,
static
LocaleNameParts
identifyBestLanguageMatch
(
const
QString
&
languageLocale
,
const
QStringList
&
availableLocales
,
const
QStringList
&
availableLocales
,
const
QString
&
countryCode
)
const
QString
&
countryCode
)
{
{
cDebug
()
<<
"Mapping"
<<
languageLocale
<<
"in"
<<
countryCode
<<
"to locale."
;
const
QString
default_lang
=
QStringLiteral
(
"en_US.UTF-8"
);
const
QString
default_lang
=
QStringLiteral
(
"en_US.UTF-8"
);
QString
lang
;
const
LocaleNameParts
self
=
LocaleNameParts
::
fromName
(
languageLocale
);
const
LocaleNameParts
self
=
LocaleNameParts
::
fromName
(
languageLocale
);
if
(
self
.
isValid
()
&&
!
availableLocales
.
isEmpty
()
)
if
(
self
.
isValid
()
&&
!
availableLocales
.
isEmpty
()
)
...
@@ -95,17 +93,22 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale,
...
@@ -95,17 +93,22 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale,
if
(
best_match
.
isValid
()
)
if
(
best_match
.
isValid
()
)
{
{
cDebug
()
<<
Logger
::
SubEntry
<<
"Matched best with"
<<
best_match
.
name
();
cDebug
()
<<
Logger
::
SubEntry
<<
"Matched best with"
<<
best_match
.
name
();
lang
=
best_match
.
name
()
;
return
best_match
;
}
}
}
}
// Else we have an unrecognized or unsupported locale, all we can do is go with
// Else we have an unrecognized or unsupported locale, all we can do is go with
// en_US.UTF-8 UTF-8. This completes all default language setting guesswork.
// en_US.UTF-8 UTF-8. This completes all default language setting guesswork.
if
(
lang
.
isEmpty
()
)
return
LocaleNameParts
::
fromName
(
default_lang
);
{
lang
=
default_lang
;
}
}
LocaleConfiguration
LocaleConfiguration
::
fromLanguageAndLocation
(
const
QString
&
languageLocale
,
const
QStringList
&
availableLocales
,
const
QString
&
countryCode
)
{
cDebug
()
<<
"Mapping"
<<
languageLocale
<<
"in"
<<
countryCode
<<
"to locale."
;
const
auto
bestLocale
=
identifyBestLanguageMatch
(
languageLocale
,
availableLocales
,
countryCode
);
// The following block was inspired by Ubiquity, scripts/localechooser-apply.
// The following block was inspired by Ubiquity, scripts/localechooser-apply.
// No copyright statement found in file, assuming GPL v2 or later.
// No copyright statement found in file, assuming GPL v2 or later.
...
@@ -153,11 +156,11 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale,
...
@@ -153,11 +156,11 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale,
// We make a proposed locale based on the UI language and the timezone's country. There is no
// We make a proposed locale based on the UI language and the timezone's country. There is no
// guarantee that this will be a valid, supported locale (often it won't).
// guarantee that this will be a valid, supported locale (often it won't).
QString
lc_formats
;
QString
lc_formats
;
const
QString
combined
=
QString
(
"%1_%2"
).
arg
(
self
.
language
).
arg
(
countryCode
);
const
QString
combined
=
QString
(
"%1_%2"
).
arg
(
bestLocale
.
language
).
arg
(
countryCode
);
if
(
availableLocales
.
contains
(
lang
)
)
if
(
availableLocales
.
contains
(
bestLocale
.
language
)
)
{
{
cDebug
()
<<
Logger
::
SubEntry
<<
"Exact formats match for language tag"
<<
lang
;
cDebug
()
<<
Logger
::
SubEntry
<<
"Exact formats match for language tag"
<<
bestLocale
.
language
;
lc_formats
=
lang
;
lc_formats
=
bestLocale
.
language
;
}
}
else
if
(
availableLocales
.
contains
(
combined
)
)
else
if
(
availableLocales
.
contains
(
combined
)
)
{
{
...
@@ -250,12 +253,7 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale,
...
@@ -250,12 +253,7 @@ LocaleConfiguration::fromLanguageAndLocation( const QString& languageLocale,
// If we cannot make a good choice for a given country we go with the LANG
// If we cannot make a good choice for a given country we go with the LANG
// setting, which defaults to en_US.UTF-8 UTF-8 if all else fails.
// setting, which defaults to en_US.UTF-8 UTF-8 if all else fails.
if
(
lc_formats
.
isEmpty
()
)
return
LocaleConfiguration
(
bestLocale
.
name
(),
lc_formats
.
isEmpty
()
?
bestLocale
.
name
()
:
lc_formats
);
{
lc_formats
=
lang
;
}
return
LocaleConfiguration
(
lang
,
lc_formats
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment