public void RefreshConfig(LocalizationType type, bool isDebug, BuildPlatform platform) { string isDebugStr = isDebug ? "_debug.xml" : "_release.xml"; //TODO Fix me string path = Application.dataPath + "/../../Settings/BuildSettings/jenkins_" + platform.ToString() + "_" + type.ToString() + isDebugStr; RefreshConfig(path); }
public void SetLanguage(LocalizationType languageType) { m_curLanguage = languageType; // 根据语言设置重载本地化表 // string dbPath = Application.persistentDataPath + "/"; // 语言包文件路径; m_dictTextWithId.Clear(); m_dictTextWithAlias.Clear(); // 从dbPath读取数据,加入两个dict // Console.Instance ().Debug (dbPath); SQLiteHelper helper = new SQLiteHelper("Localization.db"); SqliteDataReader reader = helper.ExecuteQuery("SELECT * FROM Localization"); int idOrdinal = reader.GetOrdinal("ID"); int aliasOrdinal = reader.GetOrdinal("Alias"); int textOridinal = reader.GetOrdinal(m_curLanguage.ToString()); while (reader.Read()) { int nId = reader.GetInt32(idOrdinal); string strAlias = reader.GetString(aliasOrdinal); string strText = reader.GetString(textOridinal); m_dictTextWithId [nId] = strText; m_dictTextWithAlias [strAlias] = strText; } reader.Close(); helper.CloseConnection(); Debug.LogFormat("加载了{0}条本地化记录", m_dictTextWithId.Count); }
public static Models.Localization Get(string portalId, LocalizationType type, string ns, string key, string locale) { return Repository.Current.GetResources<Models.Localization>(type.ToString(), l => l.Data.PortalId == portalId && l.Data.Namespace == ns && l.Data.Key == key && ((string.IsNullOrEmpty(l.Data.Locale) && string.IsNullOrEmpty(locale) ) || (l.Data.Locale == locale )) ).Select(l => l.Data).SingleOrDefault(); }
public static Models.Localization Get(string portalId, LocalizationType type, string ns, string key, string locale) { return(Repository.Current.GetResources <Models.Localization>(type.ToString(), l => l.Data.PortalId == portalId && l.Data.Namespace == ns && l.Data.Key == key && ((string.IsNullOrEmpty(l.Data.Locale) && string.IsNullOrEmpty(locale)) || (l.Data.Locale == locale)) ).Select(l => l.Data).SingleOrDefault()); }
public static List <Models.Localization> GetLocalizations(LocalizationType type, Func <Models.Localization, bool> query, string portalId = null) { portalId = string.IsNullOrEmpty(portalId) ? Services.Portal.CurrentPortalId : portalId; //var locs = Get(type, portalId).Where(query); var queries = GetLocalizationQueries(portalId, portalId, CurrentUserLocale); //GetLocalizationQueries(CurrentUserLocale); var resourceLocs = Repository.Current.GetResources <Models.Localization>(type.ToString(), l => l.Data.PortalId == portalId && l.Data.Key.EndsWith(".Client")); return(Repository.Current.GetResources <Models.Localization>(resourceLocs, queries, true).Select(r => r.Data).ToList()); //return queries.GetMatches(locs, true); }
public string GetTextByKey(string key) { if (string.IsNullOrEmpty(key)) { return(string.Empty); } Dictionary <string, string> dictionary; if (localizationLibrary.TryGetValue(_localization.ToString(), out dictionary)) { string result; if (dictionary.TryGetValue(key, out result)) { return(result); } } return(key); }
public static string GetLocalization(LocalizationType type, string key, string defaultText, string ns, string locale = null, string portalId = null, bool create = true) { locale = string.IsNullOrEmpty(locale) ? CurrentUserLocale : locale; portalId = string.IsNullOrEmpty(portalId) ? Services.Portal.CurrentPortalId : portalId; var text = defaultText; var loc = Repository.Current.GetResourceData <Models.Localization>(type.ToString(), key, GetLocalizationQueries(portalId, ns, locale), null); if (loc == null && create) { Services.Localization.Save(new Models.Localization() { Type = type, Key = key, Namespace = ns, Locale = null, PortalId = portalId, Text = defaultText }, Services.Account.AuditId); } else { text = loc.Text; } return(text); }
public static List <Models.Localization> Get(LocalizationType type, string portalId, string ns) { return(Repository.Current.GetResources <Models.Localization>(type.ToString(), l => l.Data.PortalId == portalId && l.Data.Namespace.IndexOf(ns) == 0).Select(l => l.Data).ToList()); }
public static void Initialize(LocalizationType type) { Language = type.ToString(); }
public static string GetPathToLocalizationFiles(LocalizationType localizationType) { return(string.Concat(PATH_TO_DATA, PATH_TO_LOCALIZATION_FILES, localizationType.ToString(), "/")); }
public static void SetLocalizationType(LocalizationType type) { string cfgPath = $"{FinalPatchConst.LOCALIZATION_DIR}/{type.ToString().ToLower()}{FinalPatchConst.LOCALIZATION_EXT}"; bool found = false; try { using (FileStream fs = File.Open(cfgPath, FileMode.Open, FileAccess.Read)) { XmlSerializer serializer = new XmlSerializer(typeof(LocalizationData)); LocalizationData data = serializer.Deserialize(fs) as LocalizationData; if (s_localizationMap == null) { s_localizationMap = new Dictionary <string, string>(); } s_localizationMap.Clear(); foreach (var item in data.items) { s_localizationMap.Add(item.Key, item.Value); } found = true; CurrentType = type; EditorPrefs.SetInt(FinalPatchConst.KEY_FINAL_PATCH_LOCALIZATION, (int)type); OnLanguageChanged?.Invoke(); } } catch { } if (!found) { // create localization file LocalizationData data = new LocalizationData() { items = new List <LocalizationItem>() { new LocalizationItem() { Key = "localization_key", Value = "localization_value", } } }; string dir = Path.GetDirectoryName(cfgPath); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } using (FileStream fs = new FileStream(cfgPath, FileMode.Create, FileAccess.Write)) { XmlSerializer serializer = new XmlSerializer(typeof(LocalizationData)); serializer.Serialize(fs, data); } Debug.LogFormat("Create Localization File:{0}", cfgPath); AssetDatabase.Refresh(); SetLocalizationType(type); } }
public static List<Models.Localization> Get(LocalizationType type, string portalId, string ns) { return Repository.Current.GetResources<Models.Localization>(type.ToString(), l => l.Data.PortalId == portalId && l.Data.Namespace.IndexOf(ns) == 0).Select(l => l.Data).ToList(); }
public static List<Models.Localization> GetLocalizations(LocalizationType type, Func<Models.Localization, bool> query, string portalId = null) { portalId = string.IsNullOrEmpty(portalId) ? Services.Portal.CurrentPortalId : portalId; //var locs = Get(type, portalId).Where(query); var queries = GetLocalizationQueries(portalId, portalId, CurrentUserLocale); //GetLocalizationQueries(CurrentUserLocale); var resourceLocs = Repository.Current.GetResources<Models.Localization>(type.ToString(), l => l.Data.PortalId == portalId && l.Data.Key.EndsWith(".Client")); return Repository.Current.GetResources<Models.Localization>(resourceLocs, queries, true).Select(r => r.Data).ToList(); //return queries.GetMatches(locs, true); }
public static string GetLocalization(LocalizationType type, string key, string defaultText, string ns, string locale = null, string portalId = null, bool create = true) { locale = string.IsNullOrEmpty(locale) ? CurrentUserLocale : locale; portalId = string.IsNullOrEmpty(portalId) ? Services.Portal.CurrentPortalId : portalId; var text = defaultText; var loc = Repository.Current.GetResourceData<Models.Localization>(type.ToString(), key, GetLocalizationQueries(portalId, ns, locale), null); if (loc == null && create) Services.Localization.Save(new Models.Localization() { Type = type, Key = key, Namespace = ns, Locale = null, PortalId = portalId, Text = defaultText }, Services.Account.AuditId); else text = loc.Text; return text; }
public static List<Models.Localization> Get(LocalizationType type, string portalId) { return Repository.Current.GetResources<Models.Localization>(type.ToString(), l => l.Data.PortalId == portalId).Select(l => l.Data).ToList(); }
public static List <Models.Localization> Get(LocalizationType type, string portalId) { return(Repository.Current.GetResources <Models.Localization>(type.ToString(), l => l.Data.PortalId == portalId).Select(l => l.Data).ToList()); }