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

Side by Side Diff: ui/base/l10n/l10n_util.h

Issue 2002783002: Use plural formats and native digits (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: plural: use "=1" instead of "one" for pop-up block infobar Created 4 years, 6 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
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutThemeMac.mm ('k') | ui/base/l10n/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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 UI_BASE_L10N_L10N_UTIL_H_ 8 #ifndef UI_BASE_L10N_L10N_UTIL_H_
9 #define UI_BASE_L10N_L10N_UTIL_H_ 9 #define UI_BASE_L10N_L10N_UTIL_H_
10 10
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // invoked with a and b offsets[0] gives the offset for a and offsets[1] the 155 // invoked with a and b offsets[0] gives the offset for a and offsets[1] the
156 // offset of b regardless of where the parameters end up in the string. 156 // offset of b regardless of where the parameters end up in the string.
157 UI_BASE_EXPORT base::string16 GetStringFUTF16(int message_id, 157 UI_BASE_EXPORT base::string16 GetStringFUTF16(int message_id,
158 const base::string16& a, 158 const base::string16& a,
159 size_t* offset); 159 size_t* offset);
160 UI_BASE_EXPORT base::string16 GetStringFUTF16(int message_id, 160 UI_BASE_EXPORT base::string16 GetStringFUTF16(int message_id,
161 const base::string16& a, 161 const base::string16& a,
162 const base::string16& b, 162 const base::string16& b,
163 std::vector<size_t>* offsets); 163 std::vector<size_t>* offsets);
164 164
165 // Convenience functions to get a string with a single number as a parameter. 165 // Convenience functions to get a string with a single integer as a parameter.
166 // The result will use non-ASCII(native) digits if required by a locale
167 // convention (e.g. Persian, Bengali).
168 // If a message requires plural formatting (e.g. "3 tabs open"), use
169 // GetPluralStringF*, instead. To format a double, integer or percentage alone
170 // without any surrounding text (e.g. "3.57", "123", "45%"), use
171 // base::Format{Double,Number,Percent}. With more than two numbers or
172 // number + surrounding text, use base::i18n::MessageFormatter.
173 // // Note that native digits have to be used in UI in general.
174 // base::{Int*,Double}ToString convert a number to a string with
175 // ASCII digits in non-UI strings.
166 UI_BASE_EXPORT base::string16 GetStringFUTF16Int(int message_id, int a); 176 UI_BASE_EXPORT base::string16 GetStringFUTF16Int(int message_id, int a);
167 base::string16 GetStringFUTF16Int(int message_id, int64_t a); 177 base::string16 GetStringFUTF16Int(int message_id, int64_t a);
168 178
169 // Get a resource string using |number| with a locale-specific plural rule. 179 // Convenience functions to format a string with a single number that requires
170 // |message_id| points to a message in the ICU syntax. 180 // plural formatting. Note that a simple 2-way rule (singular vs plural)
181 // breaks down for a number of languages. Instead of two separate messages
182 // for singular and plural, use this method with one message in ICU syntax.
171 // See http://userguide.icu-project.org/formatparse/messages and 183 // See http://userguide.icu-project.org/formatparse/messages and
172 // go/plurals (Google internal). 184 // go/plurals (Google internal) for more details and examples.
185 //
186 // For complex messages with input parameters of multiple types (int,
187 // double, time, string; e.g. "At 3:45 on Feb 3, 2016, 5 files are downloaded
188 // at 3 MB/s."), use base::i18n::MessageFormatter.
189 // message_format_unittests.cc also has more examples of plural formatting.
173 UI_BASE_EXPORT base::string16 GetPluralStringFUTF16(int message_id, int number); 190 UI_BASE_EXPORT base::string16 GetPluralStringFUTF16(int message_id, int number);
174 UI_BASE_EXPORT std::string GetPluralStringFUTF8(int message_id, int number); 191 UI_BASE_EXPORT std::string GetPluralStringFUTF8(int message_id, int number);
175 192
176 // Get a string when you only care about 'single vs multiple' distinction. 193 // Get a string when you only care about 'single vs multiple' distinction.
177 // The message pointed to by |message_id| should be in ICU syntax 194 // The message pointed to by |message_id| should be in ICU syntax
178 // (see the references above for Plural) with 'single', 'multiple', and 195 // (see the references above for Plural) with 'single', 'multiple', and
179 // 'other' (fallback) instead of 'male', 'female', and 'other' (fallback). 196 // 'other' (fallback) instead of 'male', 'female', and 'other' (fallback).
180 UI_BASE_EXPORT base::string16 GetSingleOrMultipleStringUTF16(int message_id, 197 UI_BASE_EXPORT base::string16 GetSingleOrMultipleStringUTF16(int message_id,
181 bool is_multiple); 198 bool is_multiple);
182 199
183 // In place sorting of base::string16 strings using collation rules for 200 // In place sorting of base::string16 strings using collation rules for
184 // |locale|. 201 // |locale|.
185 UI_BASE_EXPORT void SortStrings16(const std::string& locale, 202 UI_BASE_EXPORT void SortStrings16(const std::string& locale,
186 std::vector<base::string16>* strings); 203 std::vector<base::string16>* strings);
187 204
188 // Returns a vector of available locale codes. E.g., a vector containing 205 // Returns a vector of available locale codes. E.g., a vector containing
189 // en-US, es, fr, fi, pt-PT, pt-BR, etc. 206 // en-US, es, fr, fi, pt-PT, pt-BR, etc.
190 UI_BASE_EXPORT const std::vector<std::string>& GetAvailableLocales(); 207 UI_BASE_EXPORT const std::vector<std::string>& GetAvailableLocales();
191 208
192 // Returns a vector of locale codes usable for accept-languages. 209 // Returns a vector of locale codes usable for accept-languages.
193 UI_BASE_EXPORT void GetAcceptLanguagesForLocale( 210 UI_BASE_EXPORT void GetAcceptLanguagesForLocale(
194 const std::string& display_locale, 211 const std::string& display_locale,
195 std::vector<std::string>* locale_codes); 212 std::vector<std::string>* locale_codes);
196 213
197 // Returns the preferred size of the contents view of a window based on 214 // Returns the preferred size of the contents view of a window based on
198 // designer given constraints which might dependent on the language used. 215 // designer given constraints which might dependent on the language used.
199 UI_BASE_EXPORT int GetLocalizedContentsWidthInPixels(int pixel_resource_id); 216 UI_BASE_EXPORT int GetLocalizedContentsWidthInPixels(int pixel_resource_id);
200 217
201 UI_BASE_EXPORT const char* const* GetAcceptLanguageListForTesting(); 218 UI_BASE_EXPORT const char* const* GetAcceptLanguageListForTesting();
202 219
203 UI_BASE_EXPORT size_t GetAcceptLanguageListSizeForTesting(); 220 UI_BASE_EXPORT size_t GetAcceptLanguageListSizeForTesting();
204 221
205 } // namespace l10n_util 222 } // namespace l10n_util
206 223
207 #endif // UI_BASE_L10N_L10N_UTIL_H_ 224 #endif // UI_BASE_L10N_L10N_UTIL_H_
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutThemeMac.mm ('k') | ui/base/l10n/l10n_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698