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

Side by Side Diff: ui/base/l10n/formatter.cc

Issue 2747253004: Implement (FORMAT_ELAPSED, LENGTH_LONG) in time_format (Closed)
Patch Set: Created 3 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
« no previous file with comments | « no previous file | ui/base/l10n/time_format.h » ('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 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 "ui/base/l10n/formatter.h" 5 #include "ui/base/l10n/formatter.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
(...skipping 12 matching lines...) Expand all
23 int id; 23 int id;
24 const char* const fallback_one; 24 const char* const fallback_one;
25 const char* const fallback_other; 25 const char* const fallback_other;
26 }; 26 };
27 27
28 static const Pluralities IDS_ELAPSED_SHORT_SEC = { 28 static const Pluralities IDS_ELAPSED_SHORT_SEC = {
29 IDS_TIME_ELAPSED_SECS, 29 IDS_TIME_ELAPSED_SECS,
30 "one{# sec ago}", 30 "one{# sec ago}",
31 " other{# secs ago}" 31 " other{# secs ago}"
32 }; 32 };
33
34 static const Pluralities IDS_ELAPSED_LONG_SEC = {
35 IDS_TIME_ELAPSED_LONG_SECS, "one{# second ago}", " other{# seconds ago}"};
36
33 static const Pluralities IDS_ELAPSED_SHORT_MIN = { 37 static const Pluralities IDS_ELAPSED_SHORT_MIN = {
34 IDS_TIME_ELAPSED_MINS, 38 IDS_TIME_ELAPSED_MINS,
35 "one{# min ago}", 39 "one{# min ago}",
36 " other{# mins ago}" 40 " other{# mins ago}"
37 }; 41 };
42
43 static const Pluralities IDS_ELAPSED_LONG_MIN = {
44 IDS_TIME_ELAPSED_LONG_MINS, "one{# minute ago}", " other{# minutes ago}"};
45
38 static const Pluralities IDS_ELAPSED_HOUR = { 46 static const Pluralities IDS_ELAPSED_HOUR = {
39 IDS_TIME_ELAPSED_HOURS, 47 IDS_TIME_ELAPSED_HOURS,
40 "one{# hour ago}", 48 "one{# hour ago}",
41 " other{# hours ago}" 49 " other{# hours ago}"
42 }; 50 };
43 static const Pluralities IDS_ELAPSED_DAY = { 51 static const Pluralities IDS_ELAPSED_DAY = {
44 IDS_TIME_ELAPSED_DAYS, 52 IDS_TIME_ELAPSED_DAYS,
45 "one{# day ago}", 53 "one{# day ago}",
46 " other{# days ago}" 54 " other{# days ago}"
47 }; 55 };
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 if (format.get()) 266 if (format.get())
259 return format; 267 return format;
260 } 268 }
261 269
262 std::unique_ptr<icu::PluralRules> rules(BuildPluralRules()); 270 std::unique_ptr<icu::PluralRules> rules(BuildPluralRules());
263 return CreateFallbackFormat(*rules, pluralities); 271 return CreateFallbackFormat(*rules, pluralities);
264 } 272 }
265 273
266 const Formatter* FormatterContainer::Get(TimeFormat::Format format, 274 const Formatter* FormatterContainer::Get(TimeFormat::Format format,
267 TimeFormat::Length length) const { 275 TimeFormat::Length length) const {
268 DCHECK(formatter_[format][length])
269 << "Combination of FORMAT_ELAPSED and LENGTH_LONG is not implemented!";
270 return formatter_[format][length].get(); 276 return formatter_[format][length].get();
271 } 277 }
272 278
273 FormatterContainer::FormatterContainer() { 279 FormatterContainer::FormatterContainer() {
274 Initialize(); 280 Initialize();
275 } 281 }
276 282
277 FormatterContainer::~FormatterContainer() { 283 FormatterContainer::~FormatterContainer() {
278 } 284 }
279 285
280 void FormatterContainer::Initialize() { 286 void FormatterContainer::Initialize() {
281 formatter_[TimeFormat::FORMAT_ELAPSED][TimeFormat::LENGTH_SHORT].reset( 287 formatter_[TimeFormat::FORMAT_ELAPSED][TimeFormat::LENGTH_SHORT].reset(
282 new Formatter(IDS_ELAPSED_SHORT_SEC, 288 new Formatter(IDS_ELAPSED_SHORT_SEC,
283 IDS_ELAPSED_SHORT_MIN, 289 IDS_ELAPSED_SHORT_MIN,
284 IDS_ELAPSED_HOUR, 290 IDS_ELAPSED_HOUR,
285 IDS_ELAPSED_DAY)); 291 IDS_ELAPSED_DAY));
286 formatter_[TimeFormat::FORMAT_ELAPSED][TimeFormat::LENGTH_LONG].reset(); 292 formatter_[TimeFormat::FORMAT_ELAPSED][TimeFormat::LENGTH_LONG].reset(
293 new Formatter(IDS_ELAPSED_LONG_SEC, IDS_ELAPSED_LONG_MIN,
294 IDS_ELAPSED_HOUR, IDS_ELAPSED_DAY));
287 formatter_[TimeFormat::FORMAT_REMAINING][TimeFormat::LENGTH_SHORT].reset( 295 formatter_[TimeFormat::FORMAT_REMAINING][TimeFormat::LENGTH_SHORT].reset(
288 new Formatter(IDS_REMAINING_SHORT_SEC, 296 new Formatter(IDS_REMAINING_SHORT_SEC,
289 IDS_REMAINING_SHORT_MIN, 297 IDS_REMAINING_SHORT_MIN,
290 IDS_REMAINING_HOUR, 298 IDS_REMAINING_HOUR,
291 IDS_REMAINING_DAY)); 299 IDS_REMAINING_DAY));
292 formatter_[TimeFormat::FORMAT_REMAINING][TimeFormat::LENGTH_LONG].reset( 300 formatter_[TimeFormat::FORMAT_REMAINING][TimeFormat::LENGTH_LONG].reset(
293 new Formatter(IDS_REMAINING_LONG_SEC, 301 new Formatter(IDS_REMAINING_LONG_SEC,
294 IDS_REMAINING_LONG_MIN, 302 IDS_REMAINING_LONG_MIN,
295 IDS_REMAINING_HOUR, 303 IDS_REMAINING_HOUR,
296 IDS_REMAINING_DAY)); 304 IDS_REMAINING_DAY));
(...skipping 17 matching lines...) Expand all
314 322
315 void FormatterContainer::Shutdown() { 323 void FormatterContainer::Shutdown() {
316 for (int format = 0; format < TimeFormat::FORMAT_COUNT; ++format) { 324 for (int format = 0; format < TimeFormat::FORMAT_COUNT; ++format) {
317 for (int length = 0; length < TimeFormat::LENGTH_COUNT; ++length) { 325 for (int length = 0; length < TimeFormat::LENGTH_COUNT; ++length) {
318 formatter_[format][length].reset(); 326 formatter_[format][length].reset();
319 } 327 }
320 } 328 }
321 } 329 }
322 330
323 } // namespace ui 331 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | ui/base/l10n/time_format.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698