/// <summary> /// Gets available strings. /// </summary> /// <returns>Strings.</returns> public async Task <LanguageString[]> GetStringsAsync() { if (!this.stringsLoaded) { foreach (LanguageString LanguageString in await Database.Find <LanguageString>(new FilterFieldEqualTo("NamespaceId", this.objectId))) { lock (this.synchObject) { if (!this.stringsById.ContainsKey(LanguageString.Id)) { this.stringsById[LanguageString.Id] = LanguageString; } } } this.stringsLoaded = true; } lock (this.synchObject) { LanguageString[] Result = new LanguageString[this.stringsById.Count]; this.stringsById.Values.CopyTo(Result, 0); return(Result); } }
/// <summary> /// Gets the string value of a string ID. If no such string exists, a string is created with the default value. /// </summary> /// <param name="Id">String ID</param> /// <param name="Default">Default (untranslated) string.</param> /// <returns>Localized string.</returns> public async Task <string> GetStringAsync(int Id, string Default) { LanguageString StringObj = await this.GetStringAsync(Id); if (!(StringObj is null)) { return(StringObj.Value); } StringObj = await this.CreateStringAsync(Id, Default, true); return(StringObj.Value); }
/// <summary> /// Deletes a string from the namespace. /// </summary> /// <param name="Id">String ID.</param> public async Task DeleteStringAsync(int Id) { LanguageString s = await this.GetStringAsync(Id); if (s != null) { await Database.Delete(s); lock (this.synchObject) { this.stringsById.Remove(Id); } } }
/// <summary> /// Creates a new language string, or updates an existing language string, if one exist with the same properties. /// </summary> /// <param name="Id">String ID</param> /// <param name="Value">Localized value.</param> /// <param name="Untranslated">If the string is untranslated.</param> /// <returns>Namespace object.</returns> public async Task <LanguageString> CreateStringAsync(int Id, string Value, bool Untranslated) { LanguageString Result = await this.GetStringAsync(Id); if (!(Result is null)) { if (Result.Value != Value && (!Untranslated || Result.Untranslated)) { Result.Value = Value; Result.Untranslated = Untranslated; await Database.Update(Result); } return(Result); }
/// <summary> /// Creates a new language string, or updates an existing language string, if one exist with the same properties. /// </summary> /// <param name="Id">String ID</param> /// <param name="Value">Localized value.</param> /// <param name="Untranslated">If the string is untranslated.</param> /// <returns>Namespace object.</returns> public async Task <LanguageString> CreateStringAsync(int Id, string Value, bool Untranslated) { LanguageString Result = await this.GetStringAsync(Id); if (Result != null) { if (Result.Value != Value && (!Untranslated || Result.Untranslated)) { Result.Value = Value; Result.Untranslated = Untranslated; await Database.Update(Result); } return(Result); } else { Result = new LanguageString() { NamespaceId = this.objectId, Id = Id, Value = Value, Untranslated = Untranslated }; lock (synchObject) { this.stringsById[Id] = Result; } await Database.Insert(Result); return(Result); } }