Ejemplo n.º 1
0
        public static void ApplyTranslation(ITranslatable translatable)
        {
            if (!EnableTranslation)
            {
                return;
            }

            if (String.IsNullOrEmpty(translatable.Text))
            {
                return;
            }

            var defaultText = GetClearText(translatable);

            if (String.IsNullOrEmpty(translatable.TrnKey))
            {
                translatable.TrnKey = CryptographyUtil.ComputeMD5(defaultText);
            }

            translatable.Text = GetTranslatedText(translatable.TrnKey, defaultText);

            var defTranslatable = translatable as DefaultTranslatable;

            if (defTranslatable != null)
            {
                defTranslatable.Text = GetClearText(translatable);

                if (TranslationMode)
                {
                    defTranslatable.Link = GetTranslationLink(translatable);
                }
            }
        }
Ejemplo n.º 2
0
        public static String GetTranslatedText(String defaultText)
        {
            var trnKey = CryptographyUtil.ComputeMD5(defaultText);

            return(GetTranslatedText(trnKey, defaultText));
        }
Ejemplo n.º 3
0
        public static void PreloadTranslations(Control control, bool applyTranslations)
        {
            var moduleName   = PermissionUtil.ModuleName;
            var languagePair = Thread.CurrentThread.CurrentCulture.Name;


            var cache    = CommonObjectCache.InitObjectCache(trnCacheKey, () => new Dictionary <String, String>());
            var controls = UserInterfaceUtil.TraverseChildren(control);

            var query = from ctl in controls
                        let trn = ctl as ITranslatable
                                  where trn != null &&
                                  !String.IsNullOrWhiteSpace(trn.Text)
                                  let defText = GetClearText(trn.TrnKey, languagePair, trn.Text)
                                                let trnKey = (String.IsNullOrWhiteSpace(trn.TrnKey) ? CryptographyUtil.ComputeMD5(defText) : trn.TrnKey)
                                                             let cacheKey = String.Format("{0}|{1}|{2}", moduleName, trnKey, languagePair)
                                                                            select new
            {
                TrnKey       = trnKey,
                CacheKey     = cacheKey,
                DefaultText  = defText,
                Translatable = trn,
            };

            var list   = query.ToList();
            var lookup = list.ToLookup(n => n.CacheKey);

            var notInCacheControls = (from n in lookup
                                      where !ContainsCacheTranslation(cache, n.Key)
                                      select n).ToList();

            var notInCacheContracts = (from n in notInCacheControls
                                       let p = n.FirstOrDefault()
                                               let m = new TranslationContract {
                TrnKey = p.TrnKey, DefaultText = p.DefaultText
            }
                                       select m).ToList();

            var contracts = CommonProxy.GetTranslations(moduleName, languagePair, notInCacheContracts);

            foreach (var contract in contracts)
            {
                var cacheKey = String.Format("{0}|{1}|{2}", moduleName, contract.TrnKey, languagePair);
                SetCacheTranslation(cache, cacheKey, contract.TranslatedText);

                if (applyTranslations)
                {
                    foreach (var item in lookup[cacheKey])
                    {
                        var translatable = item.Translatable;

                        translatable.TrnKey = item.TrnKey;
                        translatable.Text   = contract.TranslatedText;
                    }
                }
            }
        }