Exemple #1
0
        /// <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));
            }
        }