Exemplo n.º 1
0
        private static void SetCurrentTranslations(AbstractTranslationSet newTranslations)
        {
            if (currentTranslations != newTranslations || (currentTranslations != null && !currentTranslations.Equals(newTranslations)))
            {
                currentTranslations = newTranslations;

                if (TranslationChanged != null)
                {
                    TranslationChanged();
                }
            }
        }
Exemplo n.º 2
0
        private string GetParentTranslation(string key)
        {
            AbstractTranslationSet parentTranslations = GetParentTranslations();
            string parentTranslation = null;

            if (parentTranslations != null)
            {
                CheckForLooping(parentTranslations);
                parentTranslation = parentTranslations[key];
            }

            return(parentTranslation);
        }
Exemplo n.º 3
0
        public static AbstractTranslationSet GetTranslationSet(string translationLanguage)
        {
            AbstractTranslationSet translations = null;

            if (translationLanguage != null)
            {
                translations = DictionaryUtils.GetValue(langToTranslationMap, translationLanguage);

                if (translations == null)
                {
                    translations = new ModifiableTranslationSet(translationLanguage);
                }
            }

            return(translations);
        }
Exemplo n.º 4
0
        private static void LoadTranslations(string appPath)
        {
            DirectoryInfo dir = new DirectoryInfo(Path.Combine(appPath, "translations"));

            if (!dir.Exists)
            {
                throw new TranslationLoadException("Translation path not found (" + dir.FullName + ")");
            }

            TranslationXmlLoader loader = new TranslationXmlLoader();

            foreach (FileInfo file in dir.GetFiles("*.translation"))
            {
                AbstractTranslationSet translations = loader.LoadTranslations(file.FullName);
                AddTranslationSet(translations);
            }
        }
Exemplo n.º 5
0
        private void CheckForLooping(AbstractTranslationSet translations)
        {
            bool hasLoop = false;
            AbstractTranslationSet slowLoop  = translations;
            AbstractTranslationSet fastLoop1 = translations;
            AbstractTranslationSet fastLoop2 = translations;

            while (slowLoop != null && (fastLoop1 = fastLoop2.GetParentTranslations()) != null && (fastLoop2 = fastLoop1.GetParentTranslations()) != null)
            {
                if (slowLoop.Equals(fastLoop1) || slowLoop.Equals(fastLoop2))
                {
                    hasLoop = true;
                    break;
                }

                slowLoop = slowLoop.GetParentTranslations();
            }

            if (hasLoop)
            {
                throw new TranslationLoadException("Translations contained an inheritence loop");
            }
        }
 public void SetParentTranslations(ModifiableTranslationSet parentTranslations)
 {
     parentTranslationSet = parentTranslations;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Adds the supplied translation set to the list of available translations
 /// </summary>
 /// <param name="translations">
 /// The translation set to add
 /// </param>
 public static void AddTranslationSet(AbstractTranslationSet translations)
 {
     langToTranslationMap[translations.LanguageCode] = translations;
 }