OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <iterator> | 9 #include <iterator> |
10 #include <map> | 10 #include <map> |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 for (std::map<std::string, int>::const_iterator it = language_index.begin(); | 148 for (std::map<std::string, int>::const_iterator it = language_index.begin(); |
149 it != language_index.end(); ++it) { | 149 it != language_index.end(); ++it) { |
150 const std::string& language_id = it->first; | 150 const std::string& language_id = it->first; |
151 | 151 |
152 const std::string lang = l10n_util::GetLanguage(language_id); | 152 const std::string lang = l10n_util::GetLanguage(language_id); |
153 | 153 |
154 // Ignore non-specific codes. | 154 // Ignore non-specific codes. |
155 if (lang.empty() || lang == language_id) | 155 if (lang.empty() || lang == language_id) |
156 continue; | 156 continue; |
157 | 157 |
158 if (ContainsValue(base_language_codes, language_id)) { | 158 if (base::ContainsValue(base_language_codes, language_id)) { |
159 // Language is supported. No need to replace | 159 // Language is supported. No need to replace |
160 continue; | 160 continue; |
161 } | 161 } |
162 std::string resolved_locale; | 162 std::string resolved_locale; |
163 if (!l10n_util::CheckAndResolveLocale(language_id, &resolved_locale)) | 163 if (!l10n_util::CheckAndResolveLocale(language_id, &resolved_locale)) |
164 continue; | 164 continue; |
165 | 165 |
166 if (!ContainsValue(base_language_codes, resolved_locale)) { | 166 if (!base::ContainsValue(base_language_codes, resolved_locale)) { |
167 // Resolved locale is not supported. | 167 // Resolved locale is not supported. |
168 continue; | 168 continue; |
169 } | 169 } |
170 | 170 |
171 const base::string16 display_name = | 171 const base::string16 display_name = |
172 l10n_util::GetDisplayNameForLocale(language_id, app_locale, true); | 172 l10n_util::GetDisplayNameForLocale(language_id, app_locale, true); |
173 const base::string16 native_display_name = | 173 const base::string16 native_display_name = |
174 l10n_util::GetDisplayNameForLocale( | 174 l10n_util::GetDisplayNameForLocale( |
175 language_id, language_id, true); | 175 language_id, language_id, true); |
176 | 176 |
177 language_map[display_name] = | 177 language_map[display_name] = |
178 std::make_pair(language_id, native_display_name); | 178 std::make_pair(language_id, native_display_name); |
179 | 179 |
180 most_relevant_locales_display_names[it->second] = display_name; | 180 most_relevant_locales_display_names[it->second] = display_name; |
181 ++most_relevant_locales_count; | 181 ++most_relevant_locales_count; |
182 } | 182 } |
183 | 183 |
184 // Translate language codes, generated from input methods. | 184 // Translate language codes, generated from input methods. |
185 for (std::set<std::string>::const_iterator it = language_codes.begin(); | 185 for (std::set<std::string>::const_iterator it = language_codes.begin(); |
186 it != language_codes.end(); ++it) { | 186 it != language_codes.end(); ++it) { |
187 // Exclude the language which is not in |base_langauge_codes| even it has | 187 // Exclude the language which is not in |base_langauge_codes| even it has |
188 // input methods. | 188 // input methods. |
189 if (!ContainsValue(base_language_codes, *it)) | 189 if (!base::ContainsValue(base_language_codes, *it)) |
190 continue; | 190 continue; |
191 | 191 |
192 const base::string16 display_name = | 192 const base::string16 display_name = |
193 l10n_util::GetDisplayNameForLocale(*it, app_locale, true); | 193 l10n_util::GetDisplayNameForLocale(*it, app_locale, true); |
194 const base::string16 native_display_name = | 194 const base::string16 native_display_name = |
195 l10n_util::GetDisplayNameForLocale(*it, *it, true); | 195 l10n_util::GetDisplayNameForLocale(*it, *it, true); |
196 | 196 |
197 language_map[display_name] = | 197 language_map[display_name] = std::make_pair(*it, native_display_name); |
198 std::make_pair(*it, native_display_name); | |
199 | 198 |
200 const std::map<std::string, int>::const_iterator index_pos = | 199 const std::map<std::string, int>::const_iterator index_pos = |
201 language_index.find(*it); | 200 language_index.find(*it); |
202 if (index_pos != language_index.end()) { | 201 if (index_pos != language_index.end()) { |
203 base::string16& stored_display_name = | 202 base::string16& stored_display_name = |
204 most_relevant_locales_display_names[index_pos->second]; | 203 most_relevant_locales_display_names[index_pos->second]; |
205 if (stored_display_name.empty()) { | 204 if (stored_display_name.empty()) { |
206 stored_display_name = display_name; | 205 stored_display_name = display_name; |
207 ++most_relevant_locales_count; | 206 ++most_relevant_locales_count; |
208 } | 207 } |
209 } else { | 208 } else { |
210 display_names.push_back(display_name); | 209 display_names.push_back(display_name); |
211 } | 210 } |
212 } | 211 } |
213 DCHECK_EQ(display_names.size() + most_relevant_locales_count, | 212 DCHECK_EQ(display_names.size() + most_relevant_locales_count, |
214 language_map.size()); | 213 language_map.size()); |
215 | 214 |
216 // Build the list of display names, and build the language map. | 215 // Build the list of display names, and build the language map. |
217 for (size_t i = 0; i < base_language_codes.size(); ++i) { | 216 for (size_t i = 0; i < base_language_codes.size(); ++i) { |
218 // Skip this language if it was already added. | 217 // Skip this language if it was already added. |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 std::unique_ptr<base::DictionaryValue> GetCurrentKeyboardLayout() { | 597 std::unique_ptr<base::DictionaryValue> GetCurrentKeyboardLayout() { |
599 const input_method::InputMethodDescriptor current_input_method = | 598 const input_method::InputMethodDescriptor current_input_method = |
600 input_method::InputMethodManager::Get() | 599 input_method::InputMethodManager::Get() |
601 ->GetActiveIMEState() | 600 ->GetActiveIMEState() |
602 ->GetCurrentInputMethod(); | 601 ->GetCurrentInputMethod(); |
603 return CreateInputMethodsEntry(current_input_method, | 602 return CreateInputMethodsEntry(current_input_method, |
604 current_input_method.id()); | 603 current_input_method.id()); |
605 } | 604 } |
606 | 605 |
607 } // namespace chromeos | 606 } // namespace chromeos |
OLD | NEW |