Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: chrome/browser/language_combobox_model.cc

Issue 1073005: Move RTL related functions from app/l10n_util to base/i18n/rtl... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/gtk/tabs/tab_strip_gtk.cc ('k') | chrome/browser/possible_url_model.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/language_combobox_model.h" 5 #include "chrome/browser/language_combobox_model.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/i18n/rtl.h"
8 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/metrics/user_metrics.h" 11 #include "chrome/browser/metrics/user_metrics.h"
11 #include "chrome/browser/pref_service.h" 12 #include "chrome/browser/pref_service.h"
12 #include "grit/generated_resources.h" 13 #include "grit/generated_resources.h"
13 #include "unicode/uloc.h" 14 #include "unicode/uloc.h"
14 15
15 /////////////////////////////////////////////////////////////////////////////// 16 ///////////////////////////////////////////////////////////////////////////////
16 // LanguageList used to enumerate native names corresponding to the 17 // LanguageList used to enumerate native names corresponding to the
17 // language code (e.g. English (United States) for en-US) 18 // language code (e.g. English (United States) for en-US)
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // If the name is the same in the native language and local language, 80 // If the name is the same in the native language and local language,
80 // don't show it twice. 81 // don't show it twice.
81 if (it->second.native_name == locale_names_[index]) 82 if (it->second.native_name == locale_names_[index])
82 return it->second.native_name; 83 return it->second.native_name;
83 84
84 // We must add directionality formatting to both the native name and the 85 // We must add directionality formatting to both the native name and the
85 // locale name in order to avoid text rendering problems such as misplaced 86 // locale name in order to avoid text rendering problems such as misplaced
86 // parentheses or languages appearing in the wrong order. 87 // parentheses or languages appearing in the wrong order.
87 std::wstring locale_name_localized; 88 std::wstring locale_name_localized;
88 std::wstring locale_name; 89 std::wstring locale_name;
89 if (l10n_util::AdjustStringForLocaleDirection(locale_names_[index], 90 if (base::i18n::AdjustStringForLocaleDirection(locale_names_[index],
90 &locale_name_localized)) 91 &locale_name_localized))
91 locale_name.assign(locale_name_localized); 92 locale_name.assign(locale_name_localized);
92 else 93 else
93 locale_name.assign(locale_names_[index]); 94 locale_name.assign(locale_names_[index]);
94 95
95 std::wstring native_name_localized; 96 std::wstring native_name_localized;
96 std::wstring native_name; 97 std::wstring native_name;
97 if (l10n_util::AdjustStringForLocaleDirection(it->second.native_name, 98 if (base::i18n::AdjustStringForLocaleDirection(it->second.native_name,
98 &native_name_localized)) 99 &native_name_localized))
99 native_name.assign(native_name_localized); 100 native_name.assign(native_name_localized);
100 else 101 else
101 native_name.assign(it->second.native_name); 102 native_name.assign(it->second.native_name);
102 103
103 // We used to have a localizable template here, but none of translators 104 // We used to have a localizable template here, but none of translators
104 // changed the format. We also want to switch the order of locale_name 105 // changed the format. We also want to switch the order of locale_name
105 // and native_name without going back to translators. 106 // and native_name without going back to translators.
106 std::wstring formatted_item; 107 std::wstring formatted_item;
107 SStringPrintf(&formatted_item, L"%ls - %ls", locale_name.c_str(), 108 SStringPrintf(&formatted_item, L"%ls - %ls", locale_name.c_str(),
108 native_name.c_str()); 109 native_name.c_str());
109 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) 110 if (base::i18n::IsRTL())
110 // Somehow combo box (even with LAYOUTRTL flag) doesn't get this 111 // Somehow combo box (even with LAYOUTRTL flag) doesn't get this
111 // right so we add RTL BDO (U+202E) to set the direction 112 // right so we add RTL BDO (U+202E) to set the direction
112 // explicitly. 113 // explicitly.
113 formatted_item.insert(0, L"\x202E"); 114 formatted_item.insert(0, L"\x202E");
114 return formatted_item; 115 return formatted_item;
115 } 116 }
116 117
117 // Return the locale for the given index. E.g., may return pt-BR. 118 // Return the locale for the given index. E.g., may return pt-BR.
118 std::string LanguageList::GetLocaleFromIndex(int index) const { 119 std::string LanguageList::GetLocaleFromIndex(int index) const {
119 DCHECK(static_cast<int>(locale_names_.size()) > index); 120 DCHECK(static_cast<int>(locale_names_.size()) > index);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 local_state = g_browser_process->local_state(); 163 local_state = g_browser_process->local_state();
163 else 164 else
164 local_state = profile_->GetPrefs(); 165 local_state = profile_->GetPrefs();
165 166
166 DCHECK(local_state); 167 DCHECK(local_state);
167 const std::string& current_locale = 168 const std::string& current_locale =
168 WideToASCII(local_state->GetString(prefs.c_str())); 169 WideToASCII(local_state->GetString(prefs.c_str()));
169 170
170 return GetIndexFromLocale(current_locale); 171 return GetIndexFromLocale(current_locale);
171 } 172 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/tabs/tab_strip_gtk.cc ('k') | chrome/browser/possible_url_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698