Example #1
0
        public bool AddToAssetRegistry(string key, CultureInfo culture, string value)
        {
            var selected = locale_AssetRegistry.FirstOrDefault(f => f.IsKeyEqual(key));

            if (selected != null)
            {
                if (!selected.LocaleContains(culture))
                {
                    selected.Locales.Add(culture.TwoLetterISOLanguageName.ToLower(), value);
                    //locale_AssetRegistry.Add(selected);
                }
                else
                {
                    selected.Locales[culture.TwoLetterISOLanguageName.ToLower()] = value;
                }
            }
            else
            {
                JsonLocalization njl = new JsonLocalization();
                njl.Key = key;
                njl.Locales.Add(culture.TwoLetterISOLanguageName.ToLower(), value);
                locale_AssetRegistry.Add(njl);
            }
            return(true);
        }
        public JsonLocalization ToJsonLocalization(CultureInfo languageCode)
        {
            var translate = new JsonLocalization(Id)
            {
                Locales = new Dictionary <string, string>()
                {
                    { languageCode.TwoLetterISOLanguageName, Translate_To }
                }
            };

            return(translate);
        }
Example #3
0
        private string GetString(int LocalizeType, string name, CultureInfo cultureInfo, params object[] arguments)
        {
            JsonLocalization selectedKey = null;

            switch (LocalizeType)
            {
            case 0:
            {
                selectedKey = locale_Bot.FirstOrDefault(f => f.IsKeyEqual(name));
                break;
            }

            case 1:
            {
                selectedKey = locale_AssetRegistry.FirstOrDefault(f => f.IsKeyEqual(name));
                break;
            }
            }

            if (selectedKey == null)
            {
                return("");

                throw new Exception($"undefined translation key:'{name}', Culture:'{cultureInfo}'");
            }
            string value = "";

            if (!selectedKey.LocaleContains(cultureInfo))
            {
                value = selectedKey.DefaultLocale;//default en
            }
            else
            {
                value = selectedKey.GetLocaleValue(cultureInfo);
            }
            if (arguments.Any())
            {
                value = string.Format(value, arguments);
            }
            return(value);
        }