Exemple #1
0
 /// <summary>
 /// Get all translation entities into collection
 /// </summary>
 /// <param name="reRead">ReRead from database</param>
 /// <returns>Translation collection</returns>
 public static List<sTranslate.Model.Translation> GetTranslations(bool reRead = false)
 {
     if (_translateColl == null || reRead == true)
     {
         using (var ctx = new sTranslate.Model.TranslationEntities())
         {
             _translateColl = (from xl in ctx.Translation select xl).ToList();
             if (_translateColl == null)
                 _translateColl = new List<sTranslate.Model.Translation>();
             return _translateColl;
         }
     }
     return _translateColl;
 }
Exemple #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<sTranslate.Model.Translation> coll = new List<sTranslate.Model.Translation>();
            using (var ctx = new sTranslate.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;
            }
        }
Exemple #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<sTranslate.Model.Translation> GetXltByKeys(EnumsXlt.PropertyTypes property, string context, EnumsXlt.Criterias criteria = EnumsXlt.Criterias.None, string toLanguageCode = "no")
        {
            List<sTranslate.Model.Translation> newColl = new List<sTranslate.Model.Translation>();
            if (context == null)
                return newColl;

            // Get cached collection 
            List<sTranslate.Model.Translation> translateColl = GetTranslations();

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

                // Serach matching entities
                foreach (sTranslate.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;
        }
Exemple #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<sTranslate.Model.Translation> GetTranslationByKeys(EnumsXlt.Criterias criteria, EnumsXlt.PropertyTypes property, string context = null, string toLanguageCode = "no")
        {
            List<sTranslate.Model.Translation> coll = new List<sTranslate.Model.Translation>();
            using (var ctx = new sTranslate.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<sTranslate.Model.Translation>();
            }
        }