Skip to content

Commit

Permalink
For //chrome/updater metainstaller, use preferred UI language from MUI
Browse files Browse the repository at this point in the history
For the ChromiumUpdater, instead of reading the language tag, use
GetUserPreferredUILanguageList to get the preferred UI language from
MUI.

Bug: 1281969
Change-Id: Ib5f6141a95976ada0d9c6f5964636931a7c3ff2b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3594230
Reviewed-by: Joshua Pawlicki <waffles@chromium.org>
Reviewed-by: Sorin Jianu <sorin@chromium.org>
Commit-Queue: Dong Sung Chang <donchan@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#994400}
  • Loading branch information
Michael Chang authored and Chromium LUCI CQ committed Apr 20, 2022
1 parent b1d9485 commit b5bd0f6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
18 changes: 8 additions & 10 deletions chrome/updater/win/ui/l10n_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "base/strings/sys_string_conversions.h"
#include "base/win/atl.h"
#include "base/win/embedded_i18n/language_selector.h"
#include "base/win/i18n.h"
#include "chrome/updater/tag.h"
#include "chrome/updater/util.h"
#include "chrome/updater/win/ui/resources/updater_installer_strings.h"
Expand All @@ -28,22 +29,19 @@ constexpr base::win::i18n::LanguageSelector::LangToOffset
#undef HANDLE_LANGUAGE
};

std::wstring GetPreferredLanguageFromGoogleUpdate() {
const TagParsingResult tag_parsing_result = GetTagArgs();
if (tag_parsing_result.error != tagging::ErrorCode::kSuccess) {
VLOG(0) << "Couldn't parse the tag!";
return {};
std::wstring GetPreferredLanguage() {
std::vector<std::wstring> languages;
if (!base::win::i18n::GetUserPreferredUILanguageList(&languages) ||
languages.size() == 0) {
return L"en-us";
}
const tagging::TagArgs tag_args =
tag_parsing_result.tag_args.value_or(tagging::TagArgs());

return tag_args.language.empty() ? L"en-us"
: base::SysUTF8ToWide(tag_args.language);
return languages[0];
}

const base::win::i18n::LanguageSelector& GetLanguageSelector() {
static base::NoDestructor<base::win::i18n::LanguageSelector> instance(
GetPreferredLanguageFromGoogleUpdate(), kLanguageOffsetPairs);
GetPreferredLanguage(), kLanguageOffsetPairs);
return *instance;
}

Expand Down
5 changes: 4 additions & 1 deletion docs/updater/design_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -544,4 +544,7 @@ strings. `GetLocalizedString()` uses the base id plus the offset based on the
language to look through the binary's string table to get the correct, localized
string. The formatted strings utilize GetLocalizedString() to get the string and
then uses `base::ReplaceStringPlaceholders()` to remove the `$i` placeholders
within the string.
within the string. With regards to picking the correct language to utilize for
the localized string, `base::win::i18n::GetUserPreferredUILanguageList()` is
used to get the preferred UI languages from MUI. If there are multiple languages
in the list, the first language in the list is picked.
5 changes: 3 additions & 2 deletions docs/updater/functional_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ The metainstaller parses its tag and re-launches itself at high integrity if
installing an application with `needsadmin=true` or `needsadmin=prefers`.

### Localization
Metainstaller localization presents the metainstaller UI in the language of
choice on download. Every string shown in the UI is translated.
Metainstaller localization presents the metainstaller UI with the user's
preferred language on the current system. Every string shown in the UI is
translated.

## Standalone Installer
TODO(crbug.com/1035895): Document the standalone installer.
Expand Down

0 comments on commit b5bd0f6

Please sign in to comment.