示例#1
0
        public void AddTranslationCategory(TranslationCategory translationCategory)
        {
            if (string.IsNullOrEmpty(translationCategory.Name))
            {
                throw new InvalidOperationException("Cannot add translationCategory without name");
            }

            TranslationCategories.Add(translationCategory);
        }
示例#2
0
        public TranslationCategory FindOrAddTranslationCategory(string translationCategory)
        {
            TranslationCategory tc = GetTranslationCategory(translationCategory);

            if (tc == null)
            {
                tc = new TranslationCategory(translationCategory, "en");
                AddTranslationCategory(tc);
            }
            return(tc);
        }
        public TranslationCategory FindOrAddTranslationCategory(string translationCategory)
        {
            TranslationCategory tc = GetTranslationCategory(translationCategory);

            if (tc == null)
            {
                tc = new TranslationCategory(translationCategory, SourceLanguage, TargetLanguage);
                AddTranslationCategory(tc);
            }
            return(tc);
        }
示例#4
0
        public string TranslateItem(string category, string item, string property, string defaultValue)
        {
            TranslationCategory tc = GetTranslationCategory(category);

            if (tc == null)
            {
                return(defaultValue);
            }
            TranslationItem ti = tc.Body.GetTranslationItem(item, property);

            return(ti == null || string.IsNullOrEmpty(ti.Value) ? defaultValue : ti.Value);
        }
示例#5
0
        public string TranslateItem(string category, string item, string property, Func <string> provideDefaultValue)
        {
            TranslationCategory tc = FindOrAddTranslationCategory(category);

            TranslationItem ti = tc.Body.GetTranslationItem(item, property);

            if (ti == null)
            {
                // if an item is not translated, then store its default value
                // to be able to retrieve it later (eg. when to a caption
                // is added an additional information like 'Commit (<number of changes>)',
                // and then the caption needs to be refreshed)
                string defaultValue = provideDefaultValue();
                tc.Body.AddTranslationItemIfNotExist(new TranslationItem(item, property, defaultValue));
                return(defaultValue);
            }

            if (string.IsNullOrEmpty(ti.Value))
            {
                return(ti.Source);
            }

            return(ti.Value);
        }