1 // Copyright (c) 2011 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 CHROME_BROWSER_CHROMEOS_LOGIN_LANGUAGE_LIST_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_LANGUAGE_LIST_H_ 7 8 #include <map> 9 #include <string> 10 #include <vector> 11 12 #include "base/basictypes.h" 13 #include "base/strings/string16.h" 14 15 namespace chromeos { 16 17 // LanguageList is used to enumerate native names corresponding to the 18 // language code (e.g. English (United States) for en-US). 19 class LanguageList { 20 public: 21 LanguageList(); 22 ~LanguageList(); 23 24 // Returns the number of locale names. languages_count()25 int languages_count() const { return static_cast<int>(locale_names_.size()); } 26 27 // Returns the language for the given |index|. 28 base::string16 GetLanguageNameAt(int index) const; 29 30 // Return the locale for the given |index|. E.g., may return pt-BR. 31 std::string GetLocaleFromIndex(int index) const; 32 33 // Returns the index for the given |locale|. Returns -1 if it's not found. 34 int GetIndexFromLocale(const std::string& locale) const; 35 36 // Duplicates specified languages at the beginning of the list for easier 37 // access. 38 void CopySpecifiedLanguagesUp(const std::string& locale_codes); 39 40 private: 41 struct LocaleData { LocaleDataLocaleData42 LocaleData() {} LocaleDataLocaleData43 LocaleData(const base::string16& name, const std::string& code) 44 : native_name(name), locale_code(code) {} 45 46 base::string16 native_name; 47 std::string locale_code; // E.g., en-us. 48 }; 49 50 typedef std::map<base::string16, LocaleData> LocaleDataMap; 51 52 void InitNativeNames(const std::vector<std::string>& locale_codes); 53 54 // The names of all the locales in the current application locale. 55 std::vector<base::string16> locale_names_; 56 57 // A map of some extra data (LocaleData) keyed off the name of the locale. 58 LocaleDataMap native_names_; 59 60 DISALLOW_COPY_AND_ASSIGN(LanguageList); 61 }; 62 63 } // namespace chromeos 64 65 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_LANGUAGE_LIST_H_ 66