Esempio n. 1
0
        public static void Initialize()
        {
            Localizations = new Dictionary <Language, Dictionary <string, string> >();

            // Check if the new framework-specific strings directory is available
            if (System.IO.Directory.Exists(Path.Combine(Configuration.LoadedConfiguration.LocalizerConfig.LocalizationsDirectory, "framework")))
            {
                // Populate the Dictionary for each Language
                foreach (Language language in LanguageExtensions.GetAllLanguages())
                {
                    // Read the framework JSONs
                    string path = Path.Combine(Configuration.LoadedConfiguration.LocalizerConfig.LocalizationsDirectory, "framework", language.GetCode() + ".json");

                    // Check if the file exists
                    if (File.Exists(path))
                    {
                        // Load the file
                        Localizations[language] = JsonConvert.DeserializeObject <Dictionary <string, string> >(File.ReadAllText(path));
                    }
                    else
                    {
                        // Create a new blank Dictionary
                        Localizations[language] = new Dictionary <string, string>();
                    }
                }
            }

            // Populate the Dictionary for each Language
            foreach (Language language in LanguageExtensions.GetAllLanguages())
            {
                // Create the localization file path
                string path = Path.Combine(Configuration.LoadedConfiguration.LocalizerConfig.LocalizationsDirectory, "application", language.GetCode() + ".json");

                // Check if the file exists
                if (File.Exists(path))
                {
                    // Load the file
                    Dictionary <string, string> applicationStrings = JsonConvert.DeserializeObject <Dictionary <string, string> >(File.ReadAllText(path));

                    // Get every pair
                    foreach (KeyValuePair <string, string> pair in applicationStrings)
                    {
                        // Check if this key does not exist
                        if (!Localizations[language].TryGetValue(pair.Key, out string existTestVal))
                        {
                            // Write the key into the master Dictionary
                            Localizations[language][pair.Key] = pair.Value;
                        }
                    }
                }
            }

            // Check that the localizable missing message is available
            if (!Localizations[Language.EnglishUS].TryGetValue("localizer.missing_localizable", out string missingMessage))
            {
                throw new Exception("Special message for missing localizable (\"localizer.missing_localizable\") is missing");
            }
        }
Esempio n. 2
0
        public static Dictionary <Language, string> LocalizeDateTimeToAllLanguages(DateTime dateTime)
        {
            // Create a new Dictionary
            Dictionary <Language, string> valueDict = new Dictionary <Language, string>();

            // Populate the Dictionary
            foreach (Language language in LanguageExtensions.GetAllLanguages())
            {
                // Localize the key to this Language
                valueDict.Add(language, LocalizeDateTime(dateTime, language));
            }

            // Return the Dictionary
            return(valueDict);
        }
Esempio n. 3
0
        public static Dictionary <Language, string> CreateDummyLocalizedValues(string value)
        {
            // Create a new Dictionary
            Dictionary <Language, string> valueDict = new Dictionary <Language, string>();

            // Populate the Dictionary
            foreach (Language language in LanguageExtensions.GetAllLanguages())
            {
                // Localize the key to this Language
                valueDict.Add(language, value);
            }

            // Return the Dictionary
            return(valueDict);
        }
Esempio n. 4
0
 public static Dictionary <Language, string> LocalizeToAllLanguagesWithFormat(string key, Dictionary <Language, object[]> param)
 {
     return(LocalizeToAllLanguagesWithFormat(key, LanguageExtensions.GetAllLanguages(), param));
 }
Esempio n. 5
0
 public static Dictionary <Language, string> LocalizeToAllLanguages(string key)
 {
     return(LocalizeToAllLanguages(key, LanguageExtensions.GetAllLanguages()));
 }