Commit a79ba985 authored by Wenzhao Zang's avatar Wenzhao Zang Committed by Commit Bot

cros: Delete login/language_list.cc|h

Happened to see this code that's not used anywhere.

Bug: None
Change-Id: Iab81d9125bd191d62e8f756ecfa0b4421ce8e312
Reviewed-on: https://chromium-review.googlesource.com/c/1315710Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Wenzhao (Colin) Zang <wzang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605073}
parent a1d9ff5a
...@@ -1069,8 +1069,6 @@ source_set("chromeos") { ...@@ -1069,8 +1069,6 @@ source_set("chromeos") {
"login/helper.h", "login/helper.h",
"login/hwid_checker.cc", "login/hwid_checker.cc",
"login/hwid_checker.h", "login/hwid_checker.h",
"login/language_list.cc",
"login/language_list.h",
"login/lock/screen_locker.cc", "login/lock/screen_locker.cc",
"login/lock/screen_locker.h", "login/lock/screen_locker.h",
"login/lock/views_screen_locker.cc", "login/lock/views_screen_locker.cc",
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/login/language_list.h"
#include <stddef.h>
#include "base/i18n/rtl.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "ui/base/l10n/l10n_util.h"
namespace chromeos {
LanguageList::LanguageList() {
// Enumerate the languages we know about.
const std::vector<std::string>& locale_codes =
l10n_util::GetAvailableLocales();
InitNativeNames(locale_codes);
}
LanguageList::~LanguageList() {}
base::string16 LanguageList::GetLanguageNameAt(int index) const {
DCHECK_LT(index, languages_count());
LocaleDataMap::const_iterator locale_data =
native_names_.find(locale_names_[index]);
DCHECK(locale_data != native_names_.end());
// If the name is the same in the native language and local language,
// don't show it twice.
if (locale_data->second.native_name == locale_names_[index])
return locale_data->second.native_name;
// We must add directionality formatting to both the native name and the
// locale name in order to avoid text rendering problems such as misplaced
// parentheses or languages appearing in the wrong order.
base::string16 locale_name = locale_names_[index];
base::i18n::AdjustStringForLocaleDirection(&locale_name);
base::string16 native_name = locale_data->second.native_name;
base::i18n::AdjustStringForLocaleDirection(&native_name);
// We used to have a localizable template here, but none of translators
// changed the format. We also want to switch the order of locale_name
// and native_name without going back to translators.
std::string formatted_item;
base::SStringPrintf(&formatted_item, "%s - %s",
base::UTF16ToUTF8(locale_name).c_str(),
base::UTF16ToUTF8(native_name).c_str());
if (base::i18n::IsRTL())
// Somehow combo box (even with LAYOUTRTL flag) doesn't get this
// right so we add RTL BDO (U+202E) to set the direction
// explicitly.
formatted_item.insert(0, "\xE2\x80\xAE"); // U+202E = UTF-8 0xE280AE
return base::UTF8ToUTF16(formatted_item);
}
std::string LanguageList::GetLocaleFromIndex(int index) const {
DCHECK(static_cast<int>(locale_names_.size()) > index);
LocaleDataMap::const_iterator locale_data =
native_names_.find(locale_names_[index]);
DCHECK(locale_data != native_names_.end());
return locale_data->second.locale_code;
}
int LanguageList::GetIndexFromLocale(const std::string& locale) const {
for (size_t i = 0; i < locale_names_.size(); ++i) {
LocaleDataMap::const_iterator locale_data =
native_names_.find(locale_names_[i]);
DCHECK(locale_data != native_names_.end());
if (locale_data->second.locale_code == locale)
return static_cast<int>(i);
}
return -1;
}
void LanguageList::CopySpecifiedLanguagesUp(const std::string& locale_codes) {
DCHECK(!locale_names_.empty());
for (const std::string& code : base::SplitString(
locale_codes, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
const int locale_index = GetIndexFromLocale(code);
CHECK_NE(locale_index, -1);
locale_names_.insert(locale_names_.begin(), locale_names_[locale_index]);
}
}
void LanguageList::InitNativeNames(
const std::vector<std::string>& locale_codes) {
const std::string app_locale = g_browser_process->GetApplicationLocale();
for (size_t i = 0; i < locale_codes.size(); ++i) {
const char* locale_code = locale_codes[i].c_str();
// TODO(jungshik): Even though these strings are used for the UI,
// the old code does not add an RTL mark for RTL locales. Make sure
// that it's ok without that.
base::string16 name_in_current_ui =
l10n_util::GetDisplayNameForLocale(locale_code, app_locale, false);
base::string16 name_native =
l10n_util::GetDisplayNameForLocale(locale_code, locale_code, false);
locale_names_.push_back(name_in_current_ui);
native_names_[name_in_current_ui] =
LocaleData(name_native, locale_codes[i]);
}
// Sort using locale specific sorter.
l10n_util::SortStrings16(g_browser_process->GetApplicationLocale(),
&locale_names_);
}
} // namespace chromeos
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_LANGUAGE_LIST_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_LANGUAGE_LIST_H_
#include <map>
#include <string>
#include <vector>
#include "base/macros.h"
#include "base/strings/string16.h"
namespace chromeos {
// LanguageList is used to enumerate native names corresponding to the
// language code (e.g. English (United States) for en-US).
class LanguageList {
public:
LanguageList();
~LanguageList();
// Returns the number of locale names.
int languages_count() const { return static_cast<int>(locale_names_.size()); }
// Returns the language for the given |index|.
base::string16 GetLanguageNameAt(int index) const;
// Return the locale for the given |index|. E.g., may return pt-BR.
std::string GetLocaleFromIndex(int index) const;
// Returns the index for the given |locale|. Returns -1 if it's not found.
int GetIndexFromLocale(const std::string& locale) const;
// Duplicates specified languages at the beginning of the list for easier
// access.
void CopySpecifiedLanguagesUp(const std::string& locale_codes);
private:
struct LocaleData {
LocaleData() {}
LocaleData(const base::string16& name, const std::string& code)
: native_name(name), locale_code(code) {}
base::string16 native_name;
std::string locale_code; // E.g., en-us.
};
typedef std::map<base::string16, LocaleData> LocaleDataMap;
void InitNativeNames(const std::vector<std::string>& locale_codes);
// The names of all the locales in the current application locale.
std::vector<base::string16> locale_names_;
// A map of some extra data (LocaleData) keyed off the name of the locale.
LocaleDataMap native_names_;
DISALLOW_COPY_AND_ASSIGN(LanguageList);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_LANGUAGE_LIST_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment