Beispiel #1
0
        public string getName()
        {
            var culture     = CultureHelper.getCultureName();
            var Translation = Translations.FirstOrDefault(t => t.Lang == culture);

            return(Translation.Name);
        }
Beispiel #2
0
        public ProductTranslation getCultureTranslation()
        {
            var culture     = CultureHelper.getCultureName();
            var Translation = Translations.FirstOrDefault(t => t.Lang == culture);

            return(Translation);
        }
Beispiel #3
0
        public virtual TitleDescriptionObjectTranslation GetTranslation(Int32 idUserLanguage, Int32 idDefaultLanguage, Boolean firstIsMulti, Boolean useFirstOccurence)
        {
            TitleDescriptionObjectTranslation translation = null;

            if (Translations == null || Translations.Any())
            {
                translation = Translations.Where(t => t.IdLanguage == idUserLanguage).FirstOrDefault().Translation;
            }
            if (translation == null && DefaultTranslation.IsValid() && firstIsMulti)
            {
                translation = DefaultTranslation;
            }
            if (translation == null && Translations.Any())
            {
                translation = Translations.Where(t => t.IdLanguage == idDefaultLanguage).FirstOrDefault().Translation;
            }
            if (translation == null && Translations.Any() && useFirstOccurence)
            {
                translation = Translations.FirstOrDefault().Translation;
            }
            return((translation == null) ? new TitleDescriptionObjectTranslation()
            {
                Title = Id.ToString()
            } : translation);
        }
Beispiel #4
0
        public EmailTemplate TryGetTranslation(CultureInfo culture)
        {
            var translation = Translations?.FirstOrDefault(t => t.Language == culture.Name);
            var subject     = translation?.SubjectTemplate ?? SubjectTemplate;
            var body        = translation?.BodyTemplate ?? BodyTemplate;

            return(new EmailTemplate(subject, body, culture, Name));
        }
 private string GetMessageTranslation(Problem problem, string Language)
 {
     if (Translations.Any(x => x.Code == problem.ErrorCode.Value))
     {
         return(Translations.FirstOrDefault(x => x.Code == problem.ErrorCode.Value && x.Language == Language).Text);
     }
     else
     {
         return(problem.ErrorCode.Value);
     }
 }
        public SubscriberTranslation GetTranslationItem(object code, string subref)
        {
            if (null == code)
            {
                return(null);
            }

            var translation =
                Translations.FirstOrDefault(x => x.SubRef.IsSameAs(subref) &&
                                            x.Code.IsSameAs(code.ToString()));

            return(translation);
        }
Beispiel #7
0
        private ItemTranslation GetTranslation(Int32 idLanguage, Int32 idDefault)
        {
            ItemTranslation translation = GetTranslation(idLanguage);

            if (translation == null)
            {
                translation = GetTranslation(idDefault);
                if (translation == null && Translations.Any())
                {
                    translation = Translations.FirstOrDefault();
                }
            }
            return(translation);
        }
Beispiel #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="code"></param>
        /// <param name="subref"></param>
        /// <param name="def"></param>
        /// <returns></returns>
        public string GetTranslation(object code, string subref, string def)
        {
            if (null == code)
            {
                return(def);
            }

            var translation =
                Translations.FirstOrDefault(x => x.SubRef.IsSameAs(subref) &&
                                            x.Code.IsSameAs(code.ToString()));

            if (null != translation)
            {
                return(translation.SubCode);
            }

            return(def);
        }
Beispiel #9
0
        /// <summary>
        /// Sets the translation for the specified language.
        /// </summary>
        /// <param name="parentId">The parent id</param>
        /// <param name="languageId">The language id</param>
        /// <param name="model">The model</param>
        public void SetTranslation(Guid parentId, Guid languageId, object model)
        {
            if (model is Models.GenericContent content)
            {
                var translation = Translations.FirstOrDefault(t => t.LanguageId == languageId);

                if (translation == null)
                {
                    translation = new ContentTranslation
                    {
                        ContentId  = content.Id,
                        LanguageId = languageId
                    };
                    Translations.Add(translation);
                }
                translation.Title = content.Title;
            }
        }
Beispiel #10
0
 private void TranslationAdd()
 {
     if (SelectedSentence == null)
     {
         return;
     }
     if (SelectedSentence.Translation == null)
     {
         Translation translation = Translations.FirstOrDefault(v => v.Van == SelectedSentence.Zin);
         if (translation == null)
         {
             Translations.Add(new Translation(SelectedSentence.Zin, TranslationText));
         }
     }
     else
     {
         SelectedSentence.Translation.Tot = TranslationText;
     }
 }
        public static void LoadFromStream(Stream stream)
        {
            // Binary reader for parsing of data
            using (BinaryReader reader = new BinaryReader(stream))
            {
                if (LoadingDefaults)
                {
                    // Clear translations
                    Translations.Clear();
                }

                // Get number of translations
                int count = reader.ReadInt32();

                for (int i = 0; i < count; i++)
                {
                    // Get translation
                    Translation translation = Translation.Parse(reader);

                    if (LoadingDefaults)
                    {
                        // If loading defaults, just add and skip the searching
                        Translations.Add(translation);
                        continue;
                    }

                    // Search for matching header
                    Translation match = Translations.FirstOrDefault(x => x.Header == translation.Header);

                    // If no match was found
                    if (match == null)
                    {
                        // Add translation to list
                        Translations.Add(translation);
                    }
                    else
                    {
                        // Set format to read format from config
                        match.Format = translation.Format;
                    }
                }
            }
        }
        private VirtualPathData GetTranslatedVirtualPath(VirtualPathData virtualPathData, RequestContext requestContext, RouteValueDictionary values)
        {
            if (Translations == null || !Translations.Any())
            {
                return(virtualPathData);
            }

            var currentCultureName = Thread.CurrentThread.CurrentUICulture.Name;

            // Try and get the language-culture translation, then fall back to language translation
            var translation = Translations.FirstOrDefault(t => t.CultureName == currentCultureName)
                              ?? Translations.FirstOrDefault(t => currentCultureName.StartsWith(t.CultureName));

            if (translation == null)
            {
                return(virtualPathData);
            }

            return(translation.GetVirtualPath(requestContext, values));
        }
Beispiel #13
0
        public string Translate(string culture, string context, string reference)
        {
            string result = reference;

            try
            {
                RepositoryTranslation myTranslation = Translations.FirstOrDefault(i => i.Context == context && i.Reference == reference);
                if (myTranslation != null)
                {
#if DEBUG
                    myTranslation.Usage++;
#endif
                    if (!string.IsNullOrEmpty(culture) && myTranslation.Translations.ContainsKey(culture))
                    {
                        result = myTranslation.Translations[culture];
                        if (string.IsNullOrEmpty(result))
                        {
                            result = reference;
                        }
                    }
                }
                else
                {
#if DEBUG
                    if (!UnkownTranslations.Exists(i => i.Context == context && i.Reference == reference))
                    {
                        UnkownTranslations.Add(new RepositoryTranslation()
                        {
                            Context = context, Reference = reference
                        });
                    }
#endif
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            return(result);
        }
Beispiel #14
0
        public virtual String GetTranslation(Int32 idUserLanguage, Int32 idDefaultLanguage, Boolean firstIsMulti, Boolean useFirstOccurence)
        {
            String translation = "";

            if (Translations == null || Translations.Any())
            {
                translation = Translations.Where(t => t.IdLanguage == idUserLanguage).FirstOrDefault().ToolTip;
            }
            if (String.IsNullOrEmpty(translation) && !String.IsNullOrEmpty(ToolTip) && firstIsMulti)
            {
                translation = ToolTip;
            }
            if (String.IsNullOrEmpty(translation) && Translations.Any())
            {
                translation = Translations.Where(t => t.IdLanguage == idDefaultLanguage).FirstOrDefault().ToolTip;
            }
            if (String.IsNullOrEmpty(translation) && Translations.Any() && useFirstOccurence)
            {
                translation = Translations.FirstOrDefault().ToolTip;
            }
            return((String.IsNullOrEmpty(translation)) ? Id.ToString() : translation);
        }
Beispiel #15
0
        public string?Translate(string?culture = null)
        {
            if (Translations == null)
            {
                return(null);
            }

            culture = culture?.Trim() ?? Thread.CurrentThread.CurrentUICulture.Name;

            /*
             * in database - en, en-GB
             * in query - en, en-GB, en-US
             */

            // do we have exact match - en-GB == en-GB
            var translation = Translations.FirstOrDefault(t => t.Culture == culture);

            if (translation != null)
            {
                return(translation.Value);
            }

            // do we have match without the region en-US.StartsWith(en)
            translation = Translations.FirstOrDefault(t => culture.StartsWith(t.Culture));
            if (translation != null)
            {
                return(translation.Value);
            }

            // try to find the default culture
            translation = Translations.FirstOrDefault(t => culture.StartsWith(_defaultCulture));
            if (translation != null)
            {
                return(translation.Value);
            }

            // just return the first in list or null
            return(Translations?.First().Value);
        }
Beispiel #16
0
        public void SetTranslation(string value, string culture)
        {
            if (Translations == null)
            {
                Translations = new List <LangStrTranslation>();
            }

            var translation = Translations.FirstOrDefault(t => t.Culture == culture);

            if (translation == null)
            {
                Translations.Add(new LangStrTranslation()
                {
                    Value   = value,
                    Culture = culture,
                });
            }
            else
            {
                translation.Value = value;
            }
        }
Beispiel #17
0
 public lm.Comol.Core.DomainModel.Languages.ItemObjectTranslation GetTranslation(Int32 idUserLanguage, Int32 idDefaultLanguage, Boolean firstIsMulti, Boolean useFirstOccurence)
 {
     lm.Comol.Core.DomainModel.Languages.ItemObjectTranslation translation = null;
     if (Translations != null && Translations.Any(t => t.IdLanguage == idUserLanguage))
     {
         translation = Translations.Where(t => t.IdLanguage == idUserLanguage).FirstOrDefault().Translation;
     }
     if (translation == null && DefaultTranslation.IsValid() && firstIsMulti)
     {
         translation = DefaultTranslation;
     }
     if (translation == null && Translations.Any())
     {
         translation = Translations.Where(t => t.IdLanguage == idDefaultLanguage).FirstOrDefault().Translation;
     }
     if (translation == null && Translations.Any() && useFirstOccurence)
     {
         translation = Translations.FirstOrDefault().Translation;
     }
     return((translation == null) ? new lm.Comol.Core.DomainModel.Languages.ItemObjectTranslation()
     {
         Name = Id.ToString()
     } : translation);
 }
Beispiel #18
0
 /// <summary>
 /// Gets the translation for the specified language.
 /// </summary>
 /// <param name="languageId">The language id</param>
 /// <returns>The translation</returns>
 public object GetTranslation(Guid languageId)
 {
     return(Translations.FirstOrDefault(t => t.LanguageId == languageId));
 }
Beispiel #19
0
        public bool ContainsTranslation(string translation)
        {
            var found = Translations.FirstOrDefault(pt => pt.Phrase.Equals(translation, StringComparison.OrdinalIgnoreCase));

            return(found != null);
        }
        public string GetName(int langId)
        {
            var translation = Translations.FirstOrDefault(i => i.LanguageId == langId);

            return(translation?.Name ?? string.Empty);
        }