Ejemplo n.º 1
0
 /// <summary>
 /// Get all translation entities into collection
 /// </summary>
 /// <param name="reRead">ReRead from database</param>
 /// <returns>Translation collection</returns>
 public static List<Model.Translation> GetTranslations(bool reRead = false)
 {
     if (_translateColl == null || reRead == true)
     {
         using (var ctx = new Model.TranslationEntities())
         {
             _translateColl = (from xl in ctx.Translation select xl).ToList();
             if (_translateColl == null)
                 _translateColl = new List<Model.Translation>();
             return _translateColl;
         }
     }
     return _translateColl;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 
        ///     GetToText methode returen the translated string, if defined int the Translate table. 
        ///     If the fromText is not found, the value of fromText is returned unchanged.
        ///     Multiple definitions for the same source string can be registered, and in case, 
        ///     the property and context fields must be used to separate them.    
        /// 
        /// </summary>
        /// <param name="fromText"> The string to be translated </param>
        /// <param name="context"> The context the definition is aimed for. </param>
        /// <param name="propType"> The row type. This is to be used to pinpoint the search string if multiple definitions exists </param>
        /// <returns> The translated string contained in the ToText field </returns>
        public static string GetToText(EnumsXlt.Criterias criteria, string fromText, EnumsXlt.PropertyTypes property, string context, string toLanguageCode = "no")
        {
            if (fromText.Trim() == "")
                return "";

            List<Model.Translation> coll = new List<Model.Translation>();
            using (var ctx = new Model.TranslationEntities())
            {
                if (string.IsNullOrEmpty(toLanguageCode)) 
                    toLanguageCode = "no";

                // Do search by criteria
                coll = (from xl in ctx.Translation
                        where xl.Criteria.ToLower() == criteria.ToString().ToLower() &&
                              xl.FromLang == FromLanguageCode && 
                              xl.FromText == fromText && 
                              xl.Property.ToLower() == property.ToString().ToLower() &&
                              xl.Context.ToLower() == context.ToLower() &&
                              xl.ToLang == toLanguageCode
                        select xl).ToList();

                return (coll != null && coll.Count > 0) ? coll.First().ToText : fromText;  
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="criteria"></param>
        /// <param name="propertyType"></param>
        /// <param name="context"></param>
        /// <param name="toLanguageCode"></param>
        /// <returns></returns>
        public static List<Model.Translation> GetXltByKeys(EnumsXlt.PropertyTypes property, string context, EnumsXlt.Criterias criteria = EnumsXlt.Criterias.None, string toLanguageCode = "no")
        {
            List<Model.Translation> newColl = new List<Model.Translation>();
            if (context == null)
                return newColl; 

            GetTranslations(); 
            using (var ctx = new Model.TranslationEntities())
            {
                if (string.IsNullOrEmpty(toLanguageCode))
                    toLanguageCode = "no";

                // Serach matching entities
                foreach (Model.Translation xl in _translateColl)
                {
                    if (((criteria == EnumsXlt.Criterias.None) || (criteria != EnumsXlt.Criterias.None && xl.Criteria.ToLower() == criteria.ToString().ToLower())) &&
                        xl.FromLang == FromLanguageCode &&
                        xl.Property.ToLower() == property.ToString().ToLower() &&
                        xl.Context.ToLower() == context.ToLower() &&
                        xl.ToLang == toLanguageCode)
                    {
                        newColl.Add(xl);
                    }
                }
            }
            return newColl;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Get Translation entity collection by keys 
        /// </summary>
        /// <param name="propertyType"></param>
        /// <param name="context"></param>
        /// <param name="toLanguageCode"></param>
        /// <returns></returns>
        public static List<Model.Translation> GetTranslationByKeys(EnumsXlt.Criterias criteria, EnumsXlt.PropertyTypes property, string context = null, string toLanguageCode = "no")
        {
            List<Model.Translation> coll = new List<Model.Translation>();
            using (var ctx = new Model.TranslationEntities())
            {
                if (string.IsNullOrEmpty(toLanguageCode))
                    toLanguageCode = "no";


                coll = (from xl in ctx.Translation
                        where xl.FromLang == FromLanguageCode && xl.ToLang == toLanguageCode && 
                              xl.Criteria.ToLower() == criteria.ToString().ToLower() &&  
                              xl.Property.ToLower() == property.ToString().ToLower() && 
                              (context == null || (context != null && xl.Context.ToLower() == context.ToLower()))
                        select xl).ToList();

                return (coll != null) ? coll : new List<Model.Translation>();
            }
        }