| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- #pragma once
- #include "BsCorePrerequisites.h"
- #include "BsResource.h"
- namespace BansheeEngine
- {
- /**
- * @brief Loosely based on ISO 639-1 two letter language codes
- */
- enum class Language
- {
- Afar,
- Abkhazian,
- Avestan,
- Afrikaans,
- Akan,
- Amharic,
- Aragonese,
- Arabic,
- Assamese,
- Avaric,
- Aymara,
- Azerbaijani,
- Bashkir,
- Belarusian,
- Bulgarian,
- Bihari,
- Bislama,
- Bambara,
- Bengali,
- Tibetan,
- Breton,
- Bosnian,
- Catalan,
- Chechen,
- Chamorro,
- Corsican,
- Cree,
- Czech,
- ChurchSlavic,
- Chuvash,
- Welsh,
- Danish,
- German,
- Maldivian,
- Bhutani,
- Ewe,
- Greek,
- EnglishUK,
- EnglishUS,
- Esperanto,
- Spanish,
- Estonian,
- Basque,
- Persian,
- Fulah,
- Finnish,
- Fijian,
- Faroese,
- French,
- WesternFrisian,
- Irish,
- ScottishGaelic,
- Galician,
- Guarani,
- Gujarati,
- Manx,
- Hausa,
- Hebrew,
- Hindi,
- HiriMotu,
- Croatian,
- Haitian,
- Hungarian,
- Armenian,
- Herero,
- Interlingua,
- Indonesian,
- Interlingue,
- Igbo,
- SichuanYi,
- Inupiak,
- Ido,
- Icelandic,
- Italian,
- Inuktitut,
- Japanese,
- Javanese,
- Georgian,
- Kongo,
- Kikuyu,
- Kuanyama,
- Kazakh,
- Kalaallisut,
- Cambodian,
- Kannada,
- Korean,
- Kanuri,
- Kashmiri,
- Kurdish,
- Komi,
- Cornish,
- Kirghiz,
- Latin,
- Luxembourgish,
- Ganda,
- Limburgish,
- Lingala,
- Laotian,
- Lithuanian,
- LubaKatanga,
- Latvian,
- Malagasy,
- Marshallese,
- Maori,
- Macedonian,
- Malayalam,
- Mongolian,
- Moldavian,
- Marathi,
- Malay,
- Maltese,
- Burmese,
- Nauru,
- NorwegianBokmal,
- Ndebele,
- Nepali,
- Ndonga,
- Dutch,
- NorwegianNynorsk,
- Norwegian,
- Navaho,
- Nyanja,
- Provençal,
- Ojibwa,
- Oromo,
- Oriya,
- Ossetic,
- Punjabi,
- Pali,
- Polish,
- Pushto,
- Portuguese,
- Quechua,
- Romansh,
- Kirundi,
- Romanian,
- Russian,
- Kinyarwanda,
- Sanskrit,
- Sardinian,
- Sindhi,
- NorthernSami,
- Sangro,
- Sinhalese,
- Slovak,
- Slovenian,
- Samoan,
- Shona,
- Somali,
- Albanian,
- Serbian,
- Swati,
- Sesotho,
- Sundanese,
- Swedish,
- Swahili,
- Tamil,
- Telugu,
- Tajik,
- Thai,
- Tigrinya,
- Turkmen,
- Tagalog,
- Setswana,
- Tonga,
- Turkish,
- Tsonga,
- Tatar,
- Twi,
- Tahitian,
- Uighur,
- Ukrainian,
- Urdu,
- Uzbek,
- Venda,
- Vietnamese,
- Volapuk,
- Walloon,
- Wolof,
- Xhosa,
- Yiddish,
- Yoruba,
- Zhuang,
- Chinese,
- Zulu,
- Count // Number of entries
- };
- /**
- * @brief Internal data used for representing a localized string instance.
- * e.g. a specific instance of a localized string using specific parameters.
- */
- struct LocalizedStringData
- {
- struct ParamOffset
- {
- ParamOffset()
- :paramIdx(0), location(0)
- { }
- ParamOffset(UINT32 _paramIdx, UINT32 _location)
- :paramIdx(_paramIdx), location(_location)
- { }
- UINT32 paramIdx;
- UINT32 location;
- };
- LocalizedStringData();
- ~LocalizedStringData();
- WString string;
- UINT32 numParameters;
- ParamOffset* parameterOffsets;
- void concatenateString(WString& outputString, WString* parameters, UINT32 numParameterValues) const;
- void updateString(const WString& string);
- };
- /**
- * @brief Data for a single language in the string table.
- */
- struct LanguageData
- {
- UnorderedMap<WString, SPtr<LocalizedStringData>> strings;
- };
- /**
- * @brief Class that handles string localization. Stores strings and their translations
- * in various languages, along with the ability to switch currently active language.
- */
- class BS_CORE_EXPORT StringTable : public Resource
- {
- // TODO - When editing string table I will need to ensure that all languages of the same string have the same number of parameters
- public:
- StringTable();
- ~StringTable();
- /**
- * @brief Returns all identifiers in the table.
- */
- const UnorderedSet<WString>& getIdentifiers() const { return mIdentifiers; }
- /**
- * @brief Adds or modifies string translation for the specified language.
- */
- void setString(const WString& identifier, Language language, const WString& string);
- /**
- * @brief Returns a string translation for the specified language. Returns
- * the identifier itself if one doesn't exist.
- */
- WString getString(const WString& identifier, Language language);
- /**
- * @brief Removes the string described by identifier, from all languages.
- */
- void removeString(const WString& identifier);
- /**
- * @brief Gets a string data for the specified string identifier and currently active language.
- *
- * @param identifier Unique string identifier.
- * @param insertIfNonExisting If true, a new string data for the specified identifier and language will be
- * added to the table if data doesn't already exist. The data will use the identifier as
- * the translation string.
- *
- * @return The string data. Don't store reference to this data as it may get deleted.
- */
- SPtr<LocalizedStringData> getStringData(const WString& identifier, bool insertIfNonExisting = true);
- /**
- * @brief Gets a string data for the specified string identifier and language.
- *
- * @param identifier Unique string identifier.
- * @param language Language.
- * @param insertIfNonExisting If true, a new string data for the specified identifier and language will be
- * added to the table if data doesn't already exist. The data will use the identifier as
- * the translation string.
- *
- * @return The string data. Don't store reference to this data as it may get deleted.
- */
- SPtr<LocalizedStringData> getStringData(const WString& identifier, Language language, bool insertIfNonExisting = true);
- /**
- * @brief Creates a new empty string table resource.
- */
- static HStringTable create();
- /**
- * @brief Creates a new empty string table resource.
- *
- * @note Internal method. Use "create" for normal use.
- */
- static SPtr<StringTable> _createPtr();
- static const Language DEFAULT_LANGUAGE;
- private:
- friend class HString;
- friend class StringTableManager;
- /**
- * @brief Gets the currently active language.
- */
- Language getActiveLanguage() const { return mActiveLanguage; }
- /**
- * @brief Changes the currently active language.
- * Any newly created strings will use this value.
- */
- void setActiveLanguage(Language language);
- Language mActiveLanguage;
- LanguageData* mActiveLanguageData;
- LanguageData* mDefaultLanguageData;
- LanguageData* mAllLanguages;
- UnorderedSet<WString> mIdentifiers;
- /************************************************************************/
- /* SERIALIZATION */
- /************************************************************************/
- public:
- friend class StringTableRTTI;
- static RTTITypeBase* getRTTIStatic();
- virtual RTTITypeBase* getRTTI() const override;
- };
- }
|