OLD | NEW |
---|---|
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 #include "ui/base/l10n/l10n_util.h" | 5 #include "ui/base/l10n/l10n_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstdlib> | 8 #include <cstdlib> |
9 #include <iterator> | 9 #include <iterator> |
10 #include <memory> | 10 #include <memory> |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
692 // practice, the strings should be relatively short. | 692 // practice, the strings should be relatively short. |
693 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 693 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
694 const base::string16& format_string = rb.GetLocalizedString(message_id); | 694 const base::string16& format_string = rb.GetLocalizedString(message_id); |
695 | 695 |
696 #ifndef NDEBUG | 696 #ifndef NDEBUG |
697 // Make sure every replacement string is being used, so we don't just | 697 // Make sure every replacement string is being used, so we don't just |
698 // silently fail to insert one. If |offsets| is non-NULL, then don't do this | 698 // silently fail to insert one. If |offsets| is non-NULL, then don't do this |
699 // check as the code may simply want to find the placeholders rather than | 699 // check as the code may simply want to find the placeholders rather than |
700 // actually replacing them. | 700 // actually replacing them. |
701 if (!offsets) { | 701 if (!offsets) { |
702 std::string utf8_string = base::UTF16ToUTF8(format_string); | |
703 | |
704 // $9 is the highest allowed placeholder. | 702 // $9 is the highest allowed placeholder. |
705 for (size_t i = 0; i < 9; ++i) { | 703 for (size_t i = 0; i < 9; ++i) { |
706 bool placeholder_should_exist = replacements.size() > i; | 704 bool placeholder_should_exist = replacements.size() > i; |
707 | 705 |
708 std::string placeholder = | 706 base::string16 placeholder = base::ASCIIToUTF16("$"); |
709 base::StringPrintf("$%d", static_cast<int>(i + 1)); | 707 placeholder += (L'1' + i); |
Lei Zhang
2016/05/25 00:07:02
At least Linux didn't like having this as part of
jungshik at Google
2016/05/25 07:37:05
|L'1'| is wchar_t (32-bit) on Linux/Mac. Didn't yo
jungshik at Google
2016/05/25 08:26:34
oh. trybots all come back green.
| |
710 size_t pos = utf8_string.find(placeholder.c_str()); | 708 size_t pos = format_string.find(placeholder); |
711 if (placeholder_should_exist) { | 709 if (placeholder_should_exist) { |
712 DCHECK_NE(std::string::npos, pos) << | 710 DCHECK_NE(std::string::npos, pos) << " Didn't find a " << placeholder |
Lei Zhang
2016/05/25 00:07:02
This is just "git cl format" lining things up.
| |
713 " Didn't find a " << placeholder << " placeholder in " << | 711 << " placeholder in " |
714 utf8_string; | 712 << format_string; |
715 } else { | 713 } else { |
716 DCHECK_EQ(std::string::npos, pos) << | 714 DCHECK_EQ(std::string::npos, pos) << " Unexpectedly found a " |
717 " Unexpectedly found a " << placeholder << " placeholder in " << | 715 << placeholder << " placeholder in " |
718 utf8_string; | 716 << format_string; |
719 } | 717 } |
720 } | 718 } |
721 } | 719 } |
722 #endif | 720 #endif |
723 | 721 |
724 base::string16 formatted = base::ReplaceStringPlaceholders( | 722 base::string16 formatted = base::ReplaceStringPlaceholders( |
725 format_string, replacements, offsets); | 723 format_string, replacements, offsets); |
726 AdjustParagraphDirectionality(&formatted); | 724 AdjustParagraphDirectionality(&formatted); |
727 | 725 |
728 return formatted; | 726 return formatted; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
858 } | 856 } |
859 | 857 |
860 const std::vector<std::string>& GetAvailableLocales() { | 858 const std::vector<std::string>& GetAvailableLocales() { |
861 return g_available_locales.Get(); | 859 return g_available_locales.Get(); |
862 } | 860 } |
863 | 861 |
864 void GetAcceptLanguagesForLocale(const std::string& display_locale, | 862 void GetAcceptLanguagesForLocale(const std::string& display_locale, |
865 std::vector<std::string>* locale_codes) { | 863 std::vector<std::string>* locale_codes) { |
866 for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) { | 864 for (size_t i = 0; i < arraysize(kAcceptLanguageList); ++i) { |
867 if (!l10n_util::IsLocaleNameTranslated(kAcceptLanguageList[i], | 865 if (!l10n_util::IsLocaleNameTranslated(kAcceptLanguageList[i], |
868 display_locale)) | 866 display_locale)) { |
869 // TODO(jungshik) : Put them at the of the list with language codes | 867 // TODO(jungshik) : Put them at the end of the list with language codes |
Lei Zhang
2016/05/25 00:07:03
I think that's what you meant to say?
| |
870 // enclosed by brackets instead of skipping. | 868 // enclosed by brackets instead of skipping. |
871 continue; | 869 continue; |
870 } | |
872 locale_codes->push_back(kAcceptLanguageList[i]); | 871 locale_codes->push_back(kAcceptLanguageList[i]); |
873 } | 872 } |
874 } | 873 } |
875 | 874 |
876 int GetLocalizedContentsWidthInPixels(int pixel_resource_id) { | 875 int GetLocalizedContentsWidthInPixels(int pixel_resource_id) { |
877 int width = 0; | 876 int width = 0; |
878 base::StringToInt(l10n_util::GetStringUTF8(pixel_resource_id), &width); | 877 base::StringToInt(l10n_util::GetStringUTF8(pixel_resource_id), &width); |
879 DCHECK_GT(width, 0); | 878 DCHECK_GT(width, 0); |
880 return width; | 879 return width; |
881 } | 880 } |
882 | 881 |
883 const char* const* GetAcceptLanguageListForTesting() { | 882 const char* const* GetAcceptLanguageListForTesting() { |
884 return kAcceptLanguageList; | 883 return kAcceptLanguageList; |
885 } | 884 } |
886 | 885 |
887 size_t GetAcceptLanguageListSizeForTesting() { | 886 size_t GetAcceptLanguageListSizeForTesting() { |
888 return arraysize(kAcceptLanguageList); | 887 return arraysize(kAcceptLanguageList); |
889 } | 888 } |
890 | 889 |
891 } // namespace l10n_util | 890 } // namespace l10n_util |
OLD | NEW |