Skip to content

Commit

Permalink
VPN-5643 - Ensure we always use an English backup language (#8266)
Browse files Browse the repository at this point in the history
* VPN-5643 always show a string

* typo

Co-authored-by: Francesco Lodolo <[email protected]>

* typo

Co-authored-by: Francesco Lodolo <[email protected]>

---------

Co-authored-by: Francesco Lodolo <[email protected]>
  • Loading branch information
mcleinman and flodolo authored Oct 19, 2023
1 parent ac02c2b commit f6bd991
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
5 changes: 5 additions & 0 deletions scripts/addon/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,11 @@ def qtquery(qmake, propname):
xlifftool_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "utils", "xlifftool.py")
xlifftool_cmd = [sys.executable, xlifftool_path, "-C", f"--locale={locale}", xliff_path]
xlifftool = subprocess.run(xlifftool_cmd, capture_output=True)
# This completeness metric can be out-of-date, sometimes reporting a higher-than-actual completeness after a new string is
# added to the app. This happens because the .xliff file doesn't have all the source strings, so an incorrect denominator is used.
# To show up in the .xliff, there must be a complete cycle of a new string being pulled into Pontoon (via the `extract new strings`
# job being run and merged into the translation repo) and then the VPN repo merging in a new translations commit.
# We protect against this by always loading English as a fallback language.
completeness_output = xlifftool.stdout.decode("utf-8")
completeness.append(f"{locale}:{completeness_output}")

Expand Down
5 changes: 5 additions & 0 deletions scripts/utils/import_languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ def qtquery(qmake, propname):

# Step 4
title("Write the translations.completeness file...")
# This completeness metric can be out-of-date, sometimes reporting a higher-than-actual completeness after a new string is
# added to the app. This happens because the .xliff file doesn't have all the source strings, so an incorrect denomenator is used.
# To show up in the .xliff, there must be a complete cycle of a new string being pulled into pontoon (via the `extract new strings`
# job being run and merged into the translation repo) and then the VPN repo merging in a new translations commit.
# We protect against this by always loading English as a fallback language.
with open(os.path.join(gendir, 'translations.completeness'), 'w') as file:
for l10n_file in l10n_files:
file.write(f'{l10n_file["locale"]}:{l10n_file["completeness"]}\n')
Expand Down
9 changes: 3 additions & 6 deletions src/addons/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,12 +494,9 @@ void Addon::retranslate() {

QString localeCode = Localizer::instance()->languageCodeOrSystem();

double completeness = m_translationCompleteness.value(localeCode, 0);
if (completeness < 1) {
logger.debug() << "Let's try to load another language as fallback for code"
<< localeCode;
maybeLoadLanguageFallback(localeCode);
}
logger.debug() << "Let's try to load another language as fallback for code"
<< localeCode;
maybeLoadLanguageFallback(localeCode);

QLocale locale = Localizer::instance()->locale();

Expand Down
9 changes: 3 additions & 6 deletions src/localizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,9 @@ bool Localizer::loadLanguage(const QString& requestedLocalCode) {
localeCode = systemLanguageCode();
}

double completeness = m_translationCompleteness.value(localeCode, 0);
if (completeness < 1) {
logger.debug() << "Let's try to load another language as fallback for code"
<< localeCode;
maybeLoadLanguageFallback(localeCode);
}
logger.debug() << "Let's try to load another language as fallback for code"
<< localeCode;
maybeLoadLanguageFallback(localeCode);

QLocale locale = QLocale(localeCode);
QLocale::setDefault(locale);
Expand Down

0 comments on commit f6bd991

Please sign in to comment.