コード例 #1
0
            public static string Get(string key, SystemLanguage language, params LocalisationLocalVariable[] localVariables)
            {
                MakeSureStringsAreLoaded(language);

                string text = _localisationMaps[LanguageCodes.GetLanguageCode(language)].Get(key);

                text = ReplaceVariables(text, localVariables);

                return(text);
            }
コード例 #2
0
            public static void UnloadStrings(SystemLanguage language)
            {
                if (_localisationMaps.ContainsKey(LanguageCodes.GetLanguageCode(language)))
                {
#if UNITY_EDITOR
                    EditorWarnIfDirty();
#endif
                    _localisationMaps.Remove(LanguageCodes.GetLanguageCode(language));
                }
            }
コード例 #3
0
            public static string GetRawString(string key, SystemLanguage language)
            {
                MakeSureStringsAreLoaded(language);

                if (_localisationMaps.TryGetValue(LanguageCodes.GetLanguageCode(language), out LocalisationMap map))
                {
                    return(map.Get(key, true));
                }

                return(string.Empty);
            }
コード例 #4
0
            public static bool Exists(string key, SystemLanguage language)
            {
                MakeSureStringsAreLoaded();

                if (_localisationMaps.TryGetValue(LanguageCodes.GetLanguageCode(language), out LocalisationMap map))
                {
                    return(map.IsValidKey(key));
                }

                return(false);
            }
コード例 #5
0
            public static string Get(SystemLanguage language, string key, params LocalisationLocalVariable[] localVariables)
            {
                MakeSureStringsAreLoaded(language);

                if (_localisationMaps.TryGetValue(LanguageCodes.GetLanguageCode(language), out LocalisationMap map))
                {
                    string text = map.Get(key);
                    text = ReplaceVariables(text, localVariables);

                    return(text);
                }

                return("No Localisation Map found for " + language);
            }
コード例 #6
0
            public void UpdateString(string key, SystemLanguage language, string text)
            {
                if (!string.IsNullOrEmpty(key))
                {
                    Dictionary <string, string> localisedString;

                    if (_strings.TryGetValue(key, out localisedString))
                    {
                        localisedString[LanguageCodes.GetLanguageCode(language)] = text;
                    }
                    else
                    {
                        _strings.Add(key, new Dictionary <string, string>());
                        _strings[key].Add(LanguageCodes.GetLanguageCode(language), text);
                    }
                }
            }
コード例 #7
0
            public static LocalisationGlobalVariable[] GetGlobalVariables(string key, SystemLanguage language)
            {
                if (_localisationMaps.TryGetValue(LanguageCodes.GetLanguageCode(language), out LocalisationMap map))
                {
                    string text = map.Get(key, true);

                    List <LocalisationGlobalVariable> keys = new List <LocalisationGlobalVariable>();

                    int index = 0;

                    while (index < text.Length)
                    {
                        int variableStartIndex = text.IndexOf(kVariableStartChars, index);

                        if (variableStartIndex != -1)
                        {
                            int variableEndIndex = text.IndexOf(kVariableEndChars, variableStartIndex);
                            if (variableEndIndex == -1)
                            {
                                throw new Exception("Can't find matching end bracket for variable in localised string");
                            }

                            int    variableKeyStartIndex = variableStartIndex + kVariableEndChars.Length + 1;
                            string variableKey           = text.Substring(variableKeyStartIndex, variableEndIndex - variableKeyStartIndex);

                            _globalVariables.TryGetValue(variableKey, out GlobalVariable info);
                            keys.Add(new LocalisationGlobalVariable(variableKey, info._version));

                            index = variableEndIndex + kVariableEndChars.Length;
                        }
                        else
                        {
                            break;
                        }
                    }

                    return(keys.ToArray());
                }

                return(null);
            }
コード例 #8
0
            public string GetString(string key, SystemLanguage language, SystemLanguage fallBackLanguage)
            {
                string text;
                Dictionary <string, string> localisedString;

                if (!string.IsNullOrEmpty(key) && _strings.TryGetValue(key, out localisedString))
                {
                    if (localisedString.TryGetValue(LanguageCodes.GetLanguageCode(language), out text))
                    {
                        return(text);
                    }
                    else
                    {
                        if (Application.isPlaying)
                        {
                            Debug.Log("Can't find localised version of string " + key + " for " + language);
                        }
#if DEBUG
                        if (fallBackLanguage != SystemLanguage.Unknown && fallBackLanguage != language &&
                            localisedString.TryGetValue(LanguageCodes.GetLanguageCode(fallBackLanguage), out text))
                        {
                            return(text);
                        }
                        else
                        {
                            Debug.Log("Can't find localised version of string " + key);

                            return(key + " NOT FOUND");
                        }
#endif
                    }
                }

#if DEBUG
                return("EMPTY KEY");
#else
                return(string.Empty);
#endif
            }
コード例 #9
0
            public static void LoadStrings(SystemLanguage language)
            {
                string resourceName = GetLocalisationMapName(language);
                string resourcePath = AssetUtils.GetResourcePath(LocalisationProjectSettings.Get()._localisationFolder) + "/" + resourceName;

                TextAsset       asset = Resources.Load(resourcePath) as TextAsset;
                LocalisationMap localisationMap;

                if (asset != null)
                {
                    localisationMap = Serializer.FromTextAsset <LocalisationMap>(asset);
                }
                else
                {
                    localisationMap           = new LocalisationMap();
                    localisationMap._language = language;
                }

                _localisationMaps[LanguageCodes.GetLanguageCode(language)] = localisationMap;

#if UNITY_EDITOR
                RefreshEditorKeys();
#endif
            }
コード例 #10
0
            public static bool Exists(string key)
            {
                MakeSureStringsAreLoaded();

                return(_localisationMaps[LanguageCodes.GetLanguageCode(_currentLanguage)].IsValidKey(key));
            }
コード例 #11
0
 private static string GetLocalisationMapName(SystemLanguage language)
 {
     return(kDefaultLocalisationFileName + "_" + LanguageCodes.GetLanguageCode(language).ToUpper());
 }
コード例 #12
0
            public static string GetRawString(string key, SystemLanguage language)
            {
                MakeSureStringsAreLoaded(language);

                return(_localisationMaps[LanguageCodes.GetLanguageCode(language)].Get(key, true));
            }