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

Side by Side Diff: app/l10n_util.h

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 | « app/gfx/canvas_win.cc ('k') | app/l10n_util.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 // This file contains utility functions for dealing with localized 5 // This file contains utility functions for dealing with localized
6 // content. 6 // content.
7 7
8 #ifndef APP_L10N_UTIL_H_ 8 #ifndef APP_L10N_UTIL_H_
9 #define APP_L10N_UTIL_H_ 9 #define APP_L10N_UTIL_H_
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <functional> 12 #include <functional>
13 #include <string> 13 #include <string>
14 #include <vector> 14 #include <vector>
15 15
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 17
18 #include "base/basictypes.h" 18 #include "base/basictypes.h"
19 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "base/scoped_ptr.h" 20 #include "base/scoped_ptr.h"
21 #include "base/string16.h" 21 #include "base/string16.h"
22 #include "base/string_util.h" 22 #include "base/string_util.h"
23 23
24 #if defined(OS_MACOSX) 24 #if defined(OS_MACOSX)
25 #include "app/l10n_util_mac.h" 25 #include "app/l10n_util_mac.h"
26 #endif // OS_MACOSX 26 #endif // OS_MACOSX
27 27
28 class FilePath;
29 class PrefService; 28 class PrefService;
30 29
31 namespace l10n_util { 30 namespace l10n_util {
32 31
33 const char16 kRightToLeftMark = 0x200f;
34 const char16 kLeftToRightMark = 0x200e;
35 const char16 kLeftToRightEmbeddingMark = 0x202A;
36 const char16 kRightToLeftEmbeddingMark = 0x202B;
37 const char16 kPopDirectionalFormatting = 0x202C;
38
39 // This method is responsible for determining the locale as defined below. In 32 // This method is responsible for determining the locale as defined below. In
40 // nearly all cases you shouldn't call this, rather use GetApplicationLocale 33 // nearly all cases you shouldn't call this, rather use GetApplicationLocale
41 // defined on browser_process. 34 // defined on browser_process.
42 // 35 //
43 // Returns the locale used by the Application. First we use the value from the 36 // Returns the locale used by the Application. First we use the value from the
44 // command line (--lang), second we try the value in the prefs file (passed in 37 // command line (--lang), second we try the value in the prefs file (passed in
45 // as |pref_locale|), finally, we fall back on the system locale. We only return 38 // as |pref_locale|), finally, we fall back on the system locale. We only return
46 // a value if there's a corresponding resource DLL for the locale. Otherwise, 39 // a value if there's a corresponding resource DLL for the locale. Otherwise,
47 // we fall back to en-us. 40 // we fall back to en-us.
48 std::string GetApplicationLocale(const std::wstring& pref_locale); 41 std::string GetApplicationLocale(const std::wstring& pref_locale);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 // Returns the lower case equivalent of string. 167 // Returns the lower case equivalent of string.
175 #if defined(WCHAR_T_IS_UTF32) 168 #if defined(WCHAR_T_IS_UTF32)
176 // Deprecated. The string16 version should be used instead. 169 // Deprecated. The string16 version should be used instead.
177 std::wstring ToLower(const std::wstring& string); 170 std::wstring ToLower(const std::wstring& string);
178 #endif // defined(WCHAR_T_IS_UTF32) 171 #endif // defined(WCHAR_T_IS_UTF32)
179 string16 ToLower(const string16& string); 172 string16 ToLower(const string16& string);
180 173
181 // Returns the upper case equivalent of string. 174 // Returns the upper case equivalent of string.
182 string16 ToUpper(const string16& string); 175 string16 ToUpper(const string16& string);
183 176
184 // Represents the text direction returned by the GetTextDirection() function.
185 enum TextDirection {
186 UNKNOWN_DIRECTION,
187 RIGHT_TO_LEFT,
188 LEFT_TO_RIGHT,
189 };
190
191 // Returns the text direction for the default ICU locale. It is assumed
192 // that SetICUDefaultLocale has been called to set the default locale to
193 // the UI locale of Chrome. Its return is one of the following three:
194 // * LEFT_TO_RIGHT: Left-To-Right (e.g. English, Chinese, etc.);
195 // * RIGHT_TO_LEFT: Right-To-Left (e.g. Arabic, Hebrew, etc.), and;
196 // * UNKNOWN_DIRECTION: unknown (or error).
197 TextDirection GetICUTextDirection();
198
199 // Get the application text direction. (This is just the ICU direction,
200 // except on GTK.)
201 TextDirection GetTextDirection();
202
203 // Returns the text direction for |locale_name|.
204 TextDirection GetTextDirectionForLocale(const char* locale_name);
205
206 // Given the string in |text|, returns the directionality of the first
207 // character with strong directionality in the string. If no character in the
208 // text has strong directionality, LEFT_TO_RIGHT is returned. The Bidi
209 // character types L, LRE, LRO, R, AL, RLE, and RLO are considered as strong
210 // directionality characters. Please refer to http://unicode.org/reports/tr9/
211 // for more information.
212 TextDirection GetFirstStrongCharacterDirection(const std::wstring& text);
213
214 // Given the string in |text|, this function creates a copy of the string with
215 // the appropriate Unicode formatting marks that mark the string direction
216 // (either left-to-right or right-to-left). The new string is returned in
217 // |localized_text|. The function checks both the current locale and the
218 // contents of the string in order to determine the direction of the returned
219 // string. The function returns true if the string in |text| was properly
220 // adjusted.
221 //
222 // Certain LTR strings are not rendered correctly when the context is RTL. For
223 // example, the string "Foo!" will appear as "!Foo" if it is rendered as is in
224 // an RTL context. Calling this function will make sure the returned localized
225 // string is always treated as a right-to-left string. This is done by
226 // inserting certain Unicode formatting marks into the returned string.
227 //
228 // TODO(idana) bug# 1206120: this function adjusts the string in question only
229 // if the current locale is right-to-left. The function does not take care of
230 // the opposite case (an RTL string displayed in an LTR context) since
231 // adjusting the string involves inserting Unicode formatting characters that
232 // Windows does not handle well unless right-to-left language support is
233 // installed. Since the English version of Windows doesn't have right-to-left
234 // language support installed by default, inserting the direction Unicode mark
235 // results in Windows displaying squares.
236 bool AdjustStringForLocaleDirection(const std::wstring& text,
237 std::wstring* localized_text);
238
239 // Returns true if the string contains at least one character with strong right
240 // to left directionality; that is, a character with either R or AL Unicode
241 // BiDi character type.
242 bool StringContainsStrongRTLChars(const std::wstring& text);
243
244 // Wraps a string with an LRE-PDF pair which essentialy marks the string as a
245 // Left-To-Right string. Doing this is useful in order to make sure LTR
246 // strings are rendered properly in an RTL context.
247 void WrapStringWithLTRFormatting(std::wstring* text);
248
249 // Wraps a string with an RLE-PDF pair which essentialy marks the string as a
250 // Right-To-Left string. Doing this is useful in order to make sure RTL
251 // strings are rendered properly in an LTR context.
252 void WrapStringWithRTLFormatting(std::wstring* text);
253
254 // Wraps file path to get it to display correctly in RTL UI. All filepaths
255 // should be passed through this function before display in UI for RTL locales.
256 void WrapPathWithLTRFormatting(const FilePath& path,
257 string16* rtl_safe_path);
258
259 // Given the string in |text|, this function returns the adjusted string having
260 // LTR directionality for display purpose. Which means that in RTL locale the
261 // string is wrapped with LRE (Left-To-Right Embedding) and PDF (Pop
262 // Directional Formatting) marks and returned. In LTR locale, the string itself
263 // is returned.
264 std::wstring GetDisplayStringInLTRDirectionality(std::wstring* text);
265
266 // Returns the default text alignment to be used when drawing text on a
267 // gfx::Canvas based on the directionality of the system locale language. This
268 // function is used by gfx::Canvas::DrawStringInt when the text alignment is
269 // not specified.
270 //
271 // This function returns either gfx::Canvas::TEXT_ALIGN_LEFT or
272 // gfx::Canvas::TEXT_ALIGN_RIGHT.
273 int DefaultCanvasTextAlignment();
274
275 // In place sorting of strings using collation rules for |locale|. 177 // In place sorting of strings using collation rules for |locale|.
276 // TODO(port): this should take string16. 178 // TODO(port): this should take string16.
277 void SortStrings(const std::string& locale, 179 void SortStrings(const std::string& locale,
278 std::vector<std::wstring>* strings); 180 std::vector<std::wstring>* strings);
279 181
280 // Returns a vector of available locale codes. E.g., a vector containing 182 // Returns a vector of available locale codes. E.g., a vector containing
281 // en-US, es, fr, fi, pt-PT, pt-BR, etc. 183 // en-US, es, fr, fi, pt-PT, pt-BR, etc.
282 const std::vector<std::string>& GetAvailableLocales(); 184 const std::vector<std::string>& GetAvailableLocales();
283 185
284 // Returns a vector of locale codes usable for accept-languages. 186 // Returns a vector of locale codes usable for accept-languages.
285 void GetAcceptLanguagesForLocale(const std::string& display_locale, 187 void GetAcceptLanguagesForLocale(const std::string& display_locale,
286 std::vector<std::string>* locale_codes); 188 std::vector<std::string>* locale_codes);
287 189
288 190
289 } // namespace l10n_util 191 } // namespace l10n_util
290 192
291 #endif // APP_L10N_UTIL_H_ 193 #endif // APP_L10N_UTIL_H_
OLDNEW
« no previous file with comments | « app/gfx/canvas_win.cc ('k') | app/l10n_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698