public static TranslationProto FromCrowdin(string name, string translation) { TranslationProto result = new TranslationProto(); result.Name = name; result.Translation = translation; return(result); }
/// <summary> /// Copy constructor to generate new Language data from in Game Data /// </summary> /// <param name="settings">Settings</param> /// <param name="stringProto">In game translations</param> public LanguageData(LanguageSettings settings, ProtoSet <StringProto> stringProto) { settings.VersionUpdate(); TranslationTable = new List <TranslationProto>(stringProto.Length); var translationDelegate = GetOriginalTextDelegate <StringProto>(settings); for (var i = 0; i < stringProto.dataArray.Length; i++) { var proto = stringProto.dataArray[i]; TranslationProto translationProto = new TranslationProto(); translationProto.IsValid = true; translationProto.Original = translationDelegate(proto); translationProto.Translation = translationDelegate(proto); translationProto.Name = proto.Name; TranslationTable.Add(translationProto); } }
/// <summary> /// Load and/or Dump Crowdin format translation /// </summary> /// <param name="template">Template for new language files</param> private void CrowdinDump(LanguageData template) { Func <TranslationProto, string> key = proto => $"{proto.Name}"; Func <TranslationProto, string> value = proto => proto.Translation; var translationCrowdinFilePath = Path.Combine(Settings.SettingsDirectory, LanguageData.TranslationCrowdinFileName); if (!File.Exists(translationCrowdinFilePath)) { var dict = ToCrowdinDictionary(template.TranslationTable, key, value); File.WriteAllText(translationCrowdinFilePath, JSON.ToJson(dict)); } else { var dictionary = JSON.FromJson <Dictionary <string, string> >(File.ReadAllText(translationCrowdinFilePath)); Translation = new LanguageData(); Translation.TranslationTable = new List <TranslationProto>(); foreach (var pair in dictionary) { // TODO make sure that miss matches with name and ID are handled var translationProto = TranslationProto.FromCrowdin(pair.Key, pair.Value); var match = template.TranslationTable.FirstOrDefault(proto => proto.Name == translationProto.Name); if (translationProto.Name == "string" && match != null) { translationProto.Original = match.Original; translationProto.Name = match.Name; } Translation.TranslationTable.Add(translationProto); } //Translation.UpdateTranslationItems(Settings, template); // overwrite if new translation show up var dict = ToCrowdinDictionary(Translation.TranslationTable, key, value); File.WriteAllText(translationCrowdinFilePath, JSON.ToJson(dict)); } }
public TranslationProto(TranslationProto proto, string translation) { Name = proto.Name; Original = proto.Original; Translation = translation; }