OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 declares extension specific l10n utils. | 5 // This file declares extension specific l10n utils. |
6 | 6 |
7 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_L10N_UTIL_H_ | 7 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_L10N_UTIL_H_ |
8 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_L10N_UTIL_H_ | 8 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_L10N_UTIL_H_ |
9 | 9 |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
| 12 #include <vector> |
12 | 13 |
13 class DictionaryValue; | 14 class DictionaryValue; |
14 class Extension; | 15 class Extension; |
15 class ExtensionMessageBundle; | 16 class ExtensionMessageBundle; |
16 class FilePath; | 17 class FilePath; |
17 | 18 |
18 namespace extension_l10n_util { | 19 namespace extension_l10n_util { |
19 | 20 |
20 // Returns default locale in form "en-US" or "sr" or empty string if | 21 // Returns default locale in form "en-US" or "sr" or empty string if |
21 // "default_locale" section was not defined in the manifest.json file. | 22 // "default_locale" section was not defined in the manifest.json file. |
22 std::string GetDefaultLocaleFromManifest(const DictionaryValue& manifest, | 23 std::string GetDefaultLocaleFromManifest(const DictionaryValue& manifest, |
23 std::string* error); | 24 std::string* error); |
24 | 25 |
25 // Adds locale_name to the extension if it's in chrome_locales, and | 26 // Adds locale_name to the extension if it's in chrome_locales, and |
26 // if messages file is present (we don't check content of messages file here). | 27 // if messages file is present (we don't check content of messages file here). |
27 // Returns false if locale_name was not found in chrome_locales, and sets | 28 // Returns false if locale_name was not found in chrome_locales, and sets |
28 // error with locale_name. | 29 // error with locale_name. |
29 // If file name starts with . return true (helps testing extensions under svn). | 30 // If file name starts with . return true (helps testing extensions under svn). |
30 bool AddLocale(const std::set<std::string>& chrome_locales, | 31 bool AddLocale(const std::set<std::string>& chrome_locales, |
31 const FilePath& locale_folder, | 32 const FilePath& locale_folder, |
32 const std::string& locale_name, | 33 const std::string& locale_name, |
33 std::set<std::string>* valid_locales, | 34 std::set<std::string>* valid_locales, |
34 std::string* error); | 35 std::string* error); |
35 | 36 |
| 37 // Converts all - into _, to be consistent with ICU and file system names. |
| 38 std::string NormalizeLocale(const std::string& locale); |
| 39 |
| 40 // Produce a vector of parent locales for given locale. |
| 41 // It includes the current locale in the result. |
| 42 // sr_Cyrl_RS generates sr_Cyrl_RS, sr_Cyrl and sr. |
| 43 void GetParentLocales(const std::string& current_locale, |
| 44 std::vector<std::string>* parent_locales); |
| 45 |
36 // Adds valid locales to the extension. | 46 // Adds valid locales to the extension. |
37 // 1. Do nothing if _locales directory is missing (not an error). | 47 // 1. Do nothing if _locales directory is missing (not an error). |
38 // 2. Get list of Chrome locales. | 48 // 2. Get list of Chrome locales. |
39 // 3. Enumerate all subdirectories of _locales directory. | 49 // 3. Enumerate all subdirectories of _locales directory. |
40 // 4. Intersect both lists, and add intersection to the extension. | 50 // 4. Intersect both lists, and add intersection to the extension. |
41 // Returns false if any of supplied locales don't match chrome list of locales. | 51 // Returns false if any of supplied locales don't match chrome list of locales. |
42 // Fills out error with offending locale name. | 52 // Fills out error with offending locale name. |
43 bool GetValidLocales(const FilePath& locale_path, | 53 bool GetValidLocales(const FilePath& locale_path, |
44 std::set<std::string>* locales, | 54 std::set<std::string>* locales, |
45 std::string* error); | 55 std::string* error); |
46 | 56 |
47 // Loads messages file for default locale, and application locales (application | 57 // Loads messages file for default locale, and application locales (application |
48 // locales doesn't have to exist). Application locale is current locale and its | 58 // locales doesn't have to exist). Application locale is current locale and its |
49 // parents. | 59 // parents. |
50 // Returns message bundle if it can load default locale messages file, and all | 60 // Returns message bundle if it can load default locale messages file, and all |
51 // messages are valid, else returns NULL and sets error. | 61 // messages are valid, else returns NULL and sets error. |
52 ExtensionMessageBundle* LoadMessageCatalogs( | 62 ExtensionMessageBundle* LoadMessageCatalogs( |
53 const FilePath& locale_path, | 63 const FilePath& locale_path, |
54 const std::string& default_locale, | 64 const std::string& default_locale, |
55 const std::string& app_locale, | 65 const std::string& app_locale, |
56 const std::set<std::string>& valid_locales, | 66 const std::set<std::string>& valid_locales, |
57 std::string* error); | 67 std::string* error); |
58 | 68 |
59 // Returns relative l10n path to the resource. | 69 // Returns relative l10n paths to the resource. |
60 FilePath GetL10nRelativePath(const FilePath& relative_resource_path); | 70 // Returned vector starts with more specific locale path, and ends with the |
| 71 // least specific one. |
| 72 void GetL10nRelativePaths(const FilePath& relative_resource_path, |
| 73 std::vector<FilePath>* l10n_paths); |
61 | 74 |
62 } // namespace extension_l10n_util | 75 } // namespace extension_l10n_util |
63 | 76 |
64 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_L10N_UTIL_H_ | 77 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_L10N_UTIL_H_ |
OLD | NEW |