OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef BASE_I18N_RTL_H_ |
| 6 #define BASE_I18N_RTL_H_ |
| 7 |
| 8 #include "base/string16.h" |
| 9 |
| 10 class FilePath; |
| 11 |
| 12 namespace base { |
| 13 namespace i18n { |
| 14 |
| 15 const char16 kRightToLeftMark = 0x200f; |
| 16 const char16 kLeftToRightMark = 0x200e; |
| 17 const char16 kLeftToRightEmbeddingMark = 0x202A; |
| 18 const char16 kRightToLeftEmbeddingMark = 0x202B; |
| 19 const char16 kPopDirectionalFormatting = 0x202C; |
| 20 |
| 21 // Represents the text direction returned by the GetTextDirection() function. |
| 22 enum TextDirection { |
| 23 UNKNOWN_DIRECTION, |
| 24 RIGHT_TO_LEFT, |
| 25 LEFT_TO_RIGHT, |
| 26 }; |
| 27 |
| 28 // Get language and region from the OS. |
| 29 void GetLanguageAndRegionFromOS(std::string* lang, std::string* region); |
| 30 |
| 31 // Sets the default locale of ICU. |
| 32 // Once the application locale of Chrome in GetApplicationLocale is determined, |
| 33 // the default locale of ICU need to be changed to match the application locale |
| 34 // so that ICU functions work correctly in a locale-dependent manner. |
| 35 // This is handy in that we don't have to call GetApplicationLocale() |
| 36 // everytime we call locale-dependent ICU APIs as long as we make sure |
| 37 // that this is called before any locale-dependent API is called. |
| 38 void SetICUDefaultLocale(const std::string& locale_string); |
| 39 |
| 40 // Returns the text direction for the default ICU locale. It is assumed |
| 41 // that SetICUDefaultLocale has been called to set the default locale to |
| 42 // the UI locale of Chrome. Its return is one of the following three: |
| 43 // * LEFT_TO_RIGHT: Left-To-Right (e.g. English, Chinese, etc.); |
| 44 // * RIGHT_TO_LEFT: Right-To-Left (e.g. Arabic, Hebrew, etc.), and; |
| 45 // * UNKNOWN_DIRECTION: unknown (or error). |
| 46 TextDirection GetICUTextDirection(); |
| 47 |
| 48 // Get the application text direction. (This is just the ICU direction, |
| 49 // except on GTK.) |
| 50 TextDirection GetTextDirection(); |
| 51 |
| 52 // Returns true if the application text direction is right-to-left. |
| 53 bool IsRTL(); |
| 54 |
| 55 // Returns the text direction for |locale_name|. |
| 56 TextDirection GetTextDirectionForLocale(const char* locale_name); |
| 57 |
| 58 // Given the string in |text|, returns the directionality of the first |
| 59 // character with strong directionality in the string. If no character in the |
| 60 // text has strong directionality, LEFT_TO_RIGHT is returned. The Bidi |
| 61 // character types L, LRE, LRO, R, AL, RLE, and RLO are considered as strong |
| 62 // directionality characters. Please refer to http://unicode.org/reports/tr9/ |
| 63 // for more information. |
| 64 TextDirection GetFirstStrongCharacterDirection(const std::wstring& text); |
| 65 |
| 66 // Given the string in |text|, this function creates a copy of the string with |
| 67 // the appropriate Unicode formatting marks that mark the string direction |
| 68 // (either left-to-right or right-to-left). The new string is returned in |
| 69 // |localized_text|. The function checks both the current locale and the |
| 70 // contents of the string in order to determine the direction of the returned |
| 71 // string. The function returns true if the string in |text| was properly |
| 72 // adjusted. |
| 73 // |
| 74 // Certain LTR strings are not rendered correctly when the context is RTL. For |
| 75 // example, the string "Foo!" will appear as "!Foo" if it is rendered as is in |
| 76 // an RTL context. Calling this function will make sure the returned localized |
| 77 // string is always treated as a right-to-left string. This is done by |
| 78 // inserting certain Unicode formatting marks into the returned string. |
| 79 // |
| 80 // TODO(idana) bug# 1206120: this function adjusts the string in question only |
| 81 // if the current locale is right-to-left. The function does not take care of |
| 82 // the opposite case (an RTL string displayed in an LTR context) since |
| 83 // adjusting the string involves inserting Unicode formatting characters that |
| 84 // Windows does not handle well unless right-to-left language support is |
| 85 // installed. Since the English version of Windows doesn't have right-to-left |
| 86 // language support installed by default, inserting the direction Unicode mark |
| 87 // results in Windows displaying squares. |
| 88 bool AdjustStringForLocaleDirection(const std::wstring& text, |
| 89 std::wstring* localized_text); |
| 90 |
| 91 // Returns true if the string contains at least one character with strong right |
| 92 // to left directionality; that is, a character with either R or AL Unicode |
| 93 // BiDi character type. |
| 94 bool StringContainsStrongRTLChars(const std::wstring& text); |
| 95 |
| 96 // Wraps a string with an LRE-PDF pair which essentialy marks the string as a |
| 97 // Left-To-Right string. Doing this is useful in order to make sure LTR |
| 98 // strings are rendered properly in an RTL context. |
| 99 void WrapStringWithLTRFormatting(std::wstring* text); |
| 100 |
| 101 // Wraps a string with an RLE-PDF pair which essentialy marks the string as a |
| 102 // Right-To-Left string. Doing this is useful in order to make sure RTL |
| 103 // strings are rendered properly in an LTR context. |
| 104 void WrapStringWithRTLFormatting(std::wstring* text); |
| 105 |
| 106 // Wraps file path to get it to display correctly in RTL UI. All filepaths |
| 107 // should be passed through this function before display in UI for RTL locales. |
| 108 void WrapPathWithLTRFormatting(const FilePath& path, |
| 109 string16* rtl_safe_path); |
| 110 |
| 111 // Given the string in |text|, this function returns the adjusted string having |
| 112 // LTR directionality for display purpose. Which means that in RTL locale the |
| 113 // string is wrapped with LRE (Left-To-Right Embedding) and PDF (Pop |
| 114 // Directional Formatting) marks and returned. In LTR locale, the string itself |
| 115 // is returned. |
| 116 std::wstring GetDisplayStringInLTRDirectionality(std::wstring* text); |
| 117 |
| 118 } // namespace i18n |
| 119 } // namespace base |
| 120 |
| 121 #endif // BASE_I18N_RTL_H_ |
OLD | NEW |