Exemplo n.º 1
0
        public bool UpdateLanguage(string language)
        {
            if (_configData == null || _configDataJsonNode == null)
            {
                _errorOutput.WriteLine("Error: Database not loaded");
                return(false);
            }
            if (!_configDataJsonNode.Languages.Contains(language))
            {
                _errorOutput.WriteLine("Error: Language not found");
                return(false);
            }

            if (!_configDataTranslateJsonNodes.TryGetValue(language, out var translationJsonNode))
            {
                _errorOutput.WriteLine("Error: Language json not found");
                return(false);
            }
            var updatedJsonNode            = ConfigDatabase.Build(_configDataJsonNode, translationJsonNode);
            var updatedTranslationJsonNode = ConfigDatabase.BuildTranslateNode(updatedJsonNode, _networkSourceSettings);

            using var transation = ConfigSaveTransaction.Create(updatedTranslationJsonNode,
                                                                _fileSourceSettings.DatabaseTranslateFilePath(language));
            if (!transation.Apply())
            {
                _errorOutput.WriteLine("Error: Failed update language file");
                return(false);
            }
            _configDataTranslateJsonNodes[language] = updatedTranslationJsonNode;
            transation.Commit();
            return(true);
        }
Exemplo n.º 2
0
        public bool CreateLanguage(string language)
        {
            if (_configData == null || _configDataJsonNode == null ||
                _configDataJsonNode.Languages.Contains(language))
            {
                _errorOutput.WriteLine("Error: Database not loaded");
                return(false);
            }
            if (_configDataJsonNode.Languages.Contains(language))
            {
                _errorOutput.WriteLine("Error: Language name already exist");
                return(false);
            }
            string translationJsonPath = _fileSourceSettings.DatabaseTranslateFilePath(language);

            if (File.Exists(translationJsonPath))
            {
                _errorOutput.WriteLine("Error: Language folder already exist");
                return(false);
            }
            var newTranslationJsonNode = ConfigDatabase.BuildTranslateNode(_configData, _networkSourceSettings);

            ConfigDataJsonNode.Builder builder = new ConfigDataJsonNode.Builder(_configDataJsonNode);
            builder.Languages.Add(language);
            var updatedJsonNode = builder.Build();

            Directory.CreateDirectory(Path.GetDirectoryName(translationJsonPath));
            using var trasactionGroup = new TransactionGroup(2);
            trasactionGroup.Add(ConfigSaveTransaction.Create(newTranslationJsonNode, translationJsonPath));
            trasactionGroup.Add(ConfigSaveTransaction.Create(updatedJsonNode, _fileSourceSettings.DatabaseFilePath));
            if (!trasactionGroup.Apply())
            {
                _errorOutput.WriteLine("Error: Failed write language files");
                return(false);
            }
            _configDataTranslateJsonNodes[language] = newTranslationJsonNode;
            _configDataJsonNode = updatedJsonNode;
            trasactionGroup.Commit();
            return(true);
        }