private JObject GetBlockLinks(JObject sourceBlock, JObject targetBlock, TranslationSet set, int targetSiteId)
        {
            var sourceContent = sourceBlock.Value <JArray>("content");
            var targetContent = targetBlock.Value <JArray>("content");

            var contentCount = Math.Min(sourceContent.Count, targetContent.Count);

            for (int c = 0; c < contentCount; c++)
            {
                var source = sourceContent[c] as JObject;
                var target = targetContent[c] as JObject;

                var result = ProcessLinkValue(
                    source,
                    target,
                    set,
                    targetSiteId);


                if (result != null)
                {
                    targetContent[c] = result;
                }
            }

            targetBlock["content"] = targetContent;
            return(targetBlock);
        }
Пример #2
0
        private TranslationSet CreateLocalizedValue(string value, Language language)
        {
            TranslationSet translationSet = new TranslationSet {
                Translations = new List <Translation>(), CreatedOn = DateTimeOffset.UtcNow
            };

            translationSet.Translations.Add(new Translation {
                Language = language, Text = value, ImportedOn = DateTimeOffset.UtcNow
            });
            return(translationSet);
        }
Пример #3
0
        /// <summary>
        /// Método para a tradução de um texto para o idioma atual.
        /// </summary>
        /// <param name="text">Objeto referenciado</param>
        /// <param name="key">Chave de referência da tradução</param>
        /// <param name="value">Valor da tradução</param>
        /// <returns>Texto traduzido</returns>
        public static string SetParameters(this string text, string key, object value)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException(SetParameters(Resource.ERROR_TRANSLATION_KEY_NULL_EMPTY));
            }

            if (value == null)
            {
                value = string.Empty;
            }

            var set = new TranslationSet(key, value);

            text = SetParameters(text, set);
            return(text);
        }
        public object UpdateLinkValues(TranslationSet set, int targetSiteId, object sourceValue, object targetValue)
        {
            if (set == null || sourceValue == null || targetValue == null)
            {
                return(targetValue);
            }

            var sourceJson = GetJson(sourceValue);
            var targetJson = GetJson(targetValue);

            if (sourceJson == null || targetJson == null)
            {
                return(targetValue);
            }

            if (sourceJson.ContainsKey("header") &&
                targetJson.ContainsKey("header"))
            {
                var sourceBlock = sourceJson.Value <JObject>("header");
                var targetBlock = targetJson.Value <JObject>("header");

                var result = GetBlockLinks(sourceBlock, targetBlock, set, targetSiteId);
                if (result != null)
                {
                    targetJson["header"] = result;
                }
            }

            if (sourceJson.ContainsKey("blocks") &&
                targetJson.ContainsKey("blocks"))
            {
                var sourceBlocks = sourceJson.Value <JArray>("blocks");
                var targetBlocks = targetJson.Value <JArray>("blocks");

                var commonBlockCount = Math.Min(sourceBlocks.Count, targetBlocks.Count);
                for (var b = 0; b < commonBlockCount; b++)
                {
                    var result = GetBlockLinks(sourceBlocks[b] as JObject, targetBlocks[b] as JObject, set, targetSiteId);
                    if (result != null)
                    {
                        targetBlocks[b] = result;
                    }
                }
            }
            return(JsonConvert.SerializeObject(targetJson, Formatting.Indented));
        }
Пример #5
0
        private static void Read_Languages()
        {
            #region Errors

            if (!Directory.Exists(DataPath_LanguagesDirectory))
                ZOutput.ErrorMsgWait("Error! Cannot find language resources.");

            var languages = Directory.GetDirectories(DataPath_LanguagesDirectory);
            if (languages.Length == 0)
            {
                ZOutput.ErrorMsgWait("Error! Cannot find language resources.");
            }

            #endregion

            Languages	= new LanguageSet();
            HelpSets	= new Dictionary<string, PropertyList>();
            IntroSets	= new Dictionary<string, List<string>>();
            npcNames	= new Dictionary<string, List<string>>();
            alienNames	= new Dictionary<string, List<string>>();
            starNames	= new Dictionary<string, List<string>>();

            foreach (var languagePath in languages)
            {
                var fileNames = Directory.GetFiles(languagePath, "*.txt");
                var languageName = Path.GetFileName(languagePath) ?? "Unknown";

                foreach (var fullFileName in fileNames)
                {
                    var codePage = int.Parse(File.ReadAllLines(fullFileName)[0]);
                    var encoding = Encoding.GetEncoding(codePage);

                    var fileName = Path.GetFileNameWithoutExtension(fullFileName);
                    switch (fileName)
                    {
                        case DataPath_Main:
                            #region Main resources

                            var resources = File.ReadAllLines(fullFileName, encoding);
                            var translations = new TranslationSet();
                            foreach (var resource in resources.Where(a => !string.IsNullOrEmpty(a)))
                            {
                                var tokens = resource.Split(new[] {'\t'}, StringSplitOptions.RemoveEmptyEntries);
                                if (tokens.Length > 1 && !translations.ContainsKey(tokens[0]))
                                    translations.Add(tokens[0], tokens[1].Replace("\\r\\n", "\r\n"));
                            }
                            Languages.Add(languageName, translations);
                            break;

                            #endregion

                        case DataPath_Help:
                            var propertyList = ZConfig.ReadConfig(fullFileName, encoding);
                            HelpSets.Add(languageName, propertyList);
                            break;

                        case DataPath_Intro		:	IntroSets.Add(languageName,  File.ReadAllLines(fullFileName, encoding).Where(a => a.Any(c => !char.IsDigit(c))).ToList());			break;
                        case DataPath_NPC_Names	:	npcNames.Add(languageName,   File.ReadAllLines(fullFileName, encoding).Where(a => !string.IsNullOrEmpty(a)  &&  a.Any(c => !char.IsDigit(c))).ToList());	break;
                        case DataPath_Alien_Names:	alienNames.Add(languageName, File.ReadAllLines(fullFileName, encoding).Where(a => !string.IsNullOrEmpty(a)  &&  a.Any(c => !char.IsDigit(c))).ToList());	break;
                        case DataPath_Star_Names:	starNames.Add(languageName,  File.ReadAllLines(fullFileName, encoding).Where(a => !string.IsNullOrEmpty(a)  &&  a.Any(c => !char.IsDigit(c))).ToList());	break;
                    }
                }
            }
        }
Пример #6
0
 private static void Read_GlobalProps(PropertyList propertyList)
 {
     var props = Get_ConfigProperties(propertyList["GlobalData"]);
     CurrentLanguageName		= props["Language"];
     MaxPriceChange			= int.Parse(props["MaxPriceChange"]);
     GoodIsIllegalChance		= int.Parse(props["GoodIsIllegalChance"]);
     BaseGlobalEventDuration	= int.Parse(props["BaseGlobalEventDuration"]);
     FuelMax					= int.Parse(props["FuelMax"]);
     FuelPrice				= int.Parse(props["FuelPrice"]);
     Lang = Languages[CurrentLanguageName];
 }