/// <summary>
        /// Creates a new Directory.
        /// </summary>
        /// <param name="aBundleName">bundle name for this directory</param>
        protected AbstractDirectory(string aBundleName)
            : this()
        {
            this.BundleName = aBundleName;
            // Load the bundle
            IResourceBundle bundle = ResourceBundleFactory.CreateDefaultBundle(aBundleName);

            AbstractDirectory.tagNameMap[this.GetType()] = AbstractDirectory.FillTagMap(this.GetType(), bundle);
        }
示例#2
0
        public override object InternalEvaluate(TagModel model)
        {
            IResourceBundle bundle = null;
            string          key    = GetAsString(Key, model);

            bundle = GetBundle(model);
            object[] i18nparams = GetParams(model);
            try
            {
                return(bundle.Get(key, model, i18nparams));
            } catch (Exception e)
            {
                throw TagException.EvaluationMessageError(key, e).Decorate(Context);
            }
        }
示例#3
0
        /// <summary>
        /// Registers a new string bundle for the culture
        /// </summary>
        /// <param name="bundle"></param>
        /// <returns></returns>
        public void AddBundle(IResourceBundle bundle)
        {
            if (bundle == null)
            {
                throw new ArgumentNullException("bundle");
            }

            if (bundle.CultureCode == null)
            {
                bundle.CultureCode = INVARIANT_CULTURE_KEY;
            }

            if (bundles.ContainsKey(bundle.CultureCode))
            {
                if (bundle.HasValues())
                {
                    if (bundles[bundle.CultureCode].HasValues())
                    {
                        //throw new Exception("Culture already defined: " + bundle.CultureCode);
                        string[] newkeys = bundle.GetDefinedKeys();
                        for (int i = 0; i < newkeys.Length; i++)
                        {
                            if (!bundles[bundle.CultureCode].HasString(newkeys[i]))
                            {
                                bundles[bundle.CultureCode].AddString(newkeys[i], bundle.GetString(newkeys[i]));
                            }
                        }
                    }
                    else
                    {
                        bundles[bundle.CultureCode] = bundle;
                    }
                }
            }

            if (bundle.IsInvariantCulture || INVARIANT_CULTURE_KEY == bundle.CultureCode)
            {
                bundles[INVARIANT_CULTURE_KEY] = bundle;
                _invariantCultureBundle        = bundle;
            }
            else
            {
                if (!bundles.ContainsKey(bundle.CultureCode))
                {
                    bundles.Add(bundle.CultureCode, bundle);
                }
            }
        }
        /// <summary>
        /// Gives an instance of resource bundle.
        /// </summary>
        /// <param name="aName">Name of the bundle you are looking for (ex: CanonMarkernote)</param>
        /// <param name="aCulturalInfo">a cultural info. Can be null</param>
        /// <param name="aType">a type of bundle (See USE_MANAGER or USE_TXTFILE)</param>
        /// <returns>the bundle found or loade.</returns>
        public static IResourceBundle CreateBundle(string aName, CultureInfo aCulturalInfo, int aType)
        {
            string key = aName;

            if (aCulturalInfo != null)
            {
                key += "_" + aCulturalInfo.ToString();
            }
            lock (Locker)
            {
                IResourceBundle resu = null;
                if (!ResourceBundleFactory.BUNDLES.ContainsKey(key))
                {
                    try
                    {
                        if (aType == ResourceBundleFactory.USE_MANAGER)
                        {
                            resu = new ResourceBundleWithManager(aName, aCulturalInfo);
                        }
                        else if (aType == ResourceBundleFactory.USE_TXTFILE)
                        {
                            resu = new ResourceBundle(aName, aCulturalInfo);
                        }
                    }
                    catch (Exception e)
                    {
                        Trace.TraceError("Could not load bundle '" + aName + "' (" + e.Message + ")");
                    }
                    if (resu == null || resu["TEST"] == null)
                    {
                        throw new Exception("Error while loading bundle '" + aName + "' for cultural '" + aCulturalInfo +
                                            "'");
                    }
                    ResourceBundleFactory.BUNDLES.Add(key, resu);
                }
                else
                {
                    resu = ResourceBundleFactory.BUNDLES[key];
                }

                return(resu);
            }
        }
        public SpecialResourceWriter()
        {
            // Load all bunlde
            IList <IResourceBundle> allBundle = new List <IResourceBundle>(20);

            allBundle.Add(ResourceBundleFactory.CreateBundle("CanonMarkernote", null, ResourceBundleFactory.USE_TXTFILE));
            allBundle.Add(ResourceBundleFactory.CreateBundle("CasioMarkernote", null, ResourceBundleFactory.USE_TXTFILE));
            allBundle.Add(ResourceBundleFactory.CreateBundle("Commons", null, ResourceBundleFactory.USE_TXTFILE));
            allBundle.Add(ResourceBundleFactory.CreateBundle("ExifInteropMarkernote", null, ResourceBundleFactory.USE_TXTFILE));
            allBundle.Add(ResourceBundleFactory.CreateBundle("ExifMarkernote", null, ResourceBundleFactory.USE_TXTFILE));
            allBundle.Add(ResourceBundleFactory.CreateBundle("FujiFilmMarkernote", null, ResourceBundleFactory.USE_TXTFILE));
            allBundle.Add(ResourceBundleFactory.CreateBundle("GpsMarkernote", null, ResourceBundleFactory.USE_TXTFILE));
            allBundle.Add(ResourceBundleFactory.CreateBundle("IptcMarkernote", null, ResourceBundleFactory.USE_TXTFILE));
            allBundle.Add(ResourceBundleFactory.CreateBundle("JpegMarkernote", null, ResourceBundleFactory.USE_TXTFILE));
            allBundle.Add(ResourceBundleFactory.CreateBundle("KodakMarkernote", null, ResourceBundleFactory.USE_TXTFILE));
            allBundle.Add(ResourceBundleFactory.CreateBundle("KyoceraMarkernote", null, ResourceBundleFactory.USE_TXTFILE));
            allBundle.Add(ResourceBundleFactory.CreateBundle("NikonTypeMarkernote", null, ResourceBundleFactory.USE_TXTFILE));
            allBundle.Add(ResourceBundleFactory.CreateBundle("OlympusMarkernote", null, ResourceBundleFactory.USE_TXTFILE));
            allBundle.Add(ResourceBundleFactory.CreateBundle("PanasonicMarkernote", null, ResourceBundleFactory.USE_TXTFILE));
            allBundle.Add(ResourceBundleFactory.CreateBundle("PentaxMarkernote", null, ResourceBundleFactory.USE_TXTFILE));
            allBundle.Add(ResourceBundleFactory.CreateBundle("SonyMarkernote", null, ResourceBundleFactory.USE_TXTFILE));

            IEnumerator <IResourceBundle> enumRb = allBundle.GetEnumerator();

            while (enumRb.MoveNext())
            {
                IResourceBundle bdl = enumRb.Current;
                IDictionary <string, string> idic    = bdl.Entries;
                IDictionaryEnumerator        enumDic = (IDictionaryEnumerator)idic.GetEnumerator();
                using (var rw = new ResourceWriter(bdl.Fullname + ".resources"))
                {
                    while (enumDic.MoveNext())
                    {
                        rw.AddResource((string)enumDic.Key, (string)enumDic.Value);
                    }
                }
            }
        }
        /// <summary>
        /// Fill the map with all (TAG_xxx value, BUNDLE[TAG_xxx name]).
        /// </summary>
        /// <param name="aType">where to look for fields like TAG_xxx</param>
        /// <param name="aTagMap">where to put tag found</param>
        protected static IDictionary <int, string> FillTagMap(Type aType, IResourceBundle aBundle)
        {
            FieldInfo[] lcAllContTag         = aType.GetFields();
            IDictionary <int, string> lcResu = new Dictionary <int, string>(lcAllContTag.Length);

            for (int i = 0; i < lcAllContTag.Length; i++)
            {
                string lcMemberName = lcAllContTag[i].Name;
                if (lcAllContTag[i].IsPublic && lcMemberName.StartsWith("TAG_"))
                {
                    int lcMemberValue = (int)lcAllContTag[i].GetValue(null);
                    try
                    {
                        lcResu.Add(lcMemberValue, aBundle[lcMemberName]);
                    }
                    catch (MissingResourceException mre)
                    {
                        Trace.TraceError("Could not find the key '" + aType + "' for type '" + lcMemberName + "' (" + mre.Message + ")");
                    }
                }
            }
            return(lcResu);
        }
示例#7
0
        /// <summary>
        /// Obtains a string array of the keys specifically defined
        /// for the given culture.
        /// </summary>
        /// <param name="culture"></param>
        /// <returns></returns>
        public string[] GetKeysDefinedForCulture(string culture)
        {
            IResourceBundle bundle = null;

            if (culture == INVARIANT_CULTURE_KEY)
            {
                bundle = InvariantCultureBundle;
            }
            else
            {
                if (bundles.ContainsKey(culture))
                {
                    bundle = bundles[culture];
                }
                else
                {
                    if (bundles.ContainsKey(culture.ToLower()))
                    {
                        bundle = bundles[culture.ToLower()];
                    }
                    else if (bundles.ContainsKey(culture.ToUpper()))
                    {
                        bundle = bundles[culture.ToUpper()];
                    }
                    else
                    {
                        return(new string[] { });
                    }
                }
            }
            if (bundle != null)
            {
                return(bundle.GetDefinedKeys());
            }
            return(null);
        }
示例#8
0
 public ExtendableResourceBundle(IResourceBundle baseBundle, IDictionary <string, string> extensionBundle)
 {
     _baseBundle      = baseBundle;
     _extensionBundle = extensionBundle;
 }
示例#9
0
 public CachedResourceBundle2(IResourceBundle bundle)
 {
     this.bundle = bundle ?? throw new ArgumentNullException(nameof(bundle));
 }
 /// <summary>
 /// Fill the map with all (TAG_xxx value, BUNDLE[TAG_xxx name]).
 /// </summary>
 /// <param name="aType">where to look for fields like TAG_xxx</param>
 /// <param name="aTagMap">where to put tag found</param>
 protected static IDictionary<int, string> FillTagMap(Type aType, IResourceBundle aBundle)
 {
     FieldInfo[] lcAllContTag = aType.GetFields();
     IDictionary<int, string> lcResu = new Dictionary<int, string>(lcAllContTag.Length);
     for (int i = 0; i < lcAllContTag.Length; i++)
     {
         string lcMemberName = lcAllContTag[i].Name;
         if (lcAllContTag[i].IsPublic && lcMemberName.StartsWith("TAG_"))
         {
             int lcMemberValue = (int)lcAllContTag[i].GetValue(null);
             try
             {
                 lcResu.Add(lcMemberValue, aBundle[lcMemberName]);
             }
             catch (MissingResourceException mre)
             {
                 Trace.TraceError("Could not find the key '" + aType + "' for type '" + lcMemberName + "' (" + mre.Message + ")");
             }
         }
     }
     return lcResu;
 }