コード例 #1
0
		/// <summary>
		/// Default construtor
		/// </summary>
		/// <param name="getLanguage">Must return language name for localized values the localizer will provide</param>
		/// <param name="filename">Localization filename</param>
		public LocaleManager(Func<string> getLanguage, string filename) : this()
		{
			if (getLanguage == null)
			{
				throw new ArgumentNullException("getLanguage");
			}

			this._getLanguage = getLanguage;

			var document = new XmlDocument();

			document.Load(filename);

			foreach (XmlNode childNode in document.DocumentElement.ChildNodes)
			{
				foreach (XmlNode formNode in childNode.ChildNodes)
				{
					var formInfo = new LocaleFormInfo(formNode.Name);

					foreach (XmlNode resourceNode in formNode.ChildNodes)
					{
						var resourceInfo = new LocaleResourceInfo(resourceNode.Name);

						foreach (XmlNode i18nNode in resourceNode.ChildNodes)
						{
							var localeItem = new LocaleItemInfo(
								i18nNode.Attributes["name"].Value,
								i18nNode.InnerText.RemoveWhitespaces()
							);

							resourceInfo.AddLocaleItem(localeItem);
						}

						formInfo.AddResource(resourceInfo);
					}

					this._resources.Add(formInfo.Name, formInfo);
				}
			}
		}
コード例 #2
0
        /// <summary>
        /// Default construtor
        /// </summary>
        /// <param name="getLanguage">Must return language name for localized values the localizer will provide</param>
        /// <param name="filename">Localization filename</param>
        public LocaleManager(Func <string> getLanguage, string filename) : this()
        {
            if (getLanguage == null)
            {
                throw new ArgumentNullException("getLanguage");
            }

            this._getLanguage = getLanguage;

            var document = new XmlDocument();

            document.Load(filename);

            foreach (XmlNode childNode in document.DocumentElement.ChildNodes)
            {
                foreach (XmlNode formNode in childNode.ChildNodes)
                {
                    var formInfo = new LocaleFormInfo(formNode.Name);

                    foreach (XmlNode resourceNode in formNode.ChildNodes)
                    {
                        var resourceInfo = new LocaleResourceInfo(resourceNode.Name);

                        foreach (XmlNode i18nNode in resourceNode.ChildNodes)
                        {
                            var localeItem = new LocaleItemInfo(
                                i18nNode.Attributes["name"].Value,
                                i18nNode.InnerText.RemoveWhitespaces()
                                );

                            resourceInfo.AddLocaleItem(localeItem);
                        }

                        formInfo.AddResource(resourceInfo);
                    }

                    this._resources.Add(formInfo.Name, formInfo);
                }
            }
        }
コード例 #3
0
 /// <summary>
 /// Add localization item
 /// </summary>
 /// <param name="localeItemInfo">Localization item</param>
 internal void AddLocaleItem(LocaleItemInfo localeItemInfo)
 {
     this._localeItems.Add(localeItemInfo.Language, localeItemInfo);
 }
コード例 #4
0
		/// <summary>
		/// Add localization item
		/// </summary>
		/// <param name="localeItemInfo">Localization item</param>
		internal void AddLocaleItem(LocaleItemInfo localeItemInfo)
		{
			this._localeItems.Add(localeItemInfo.Language, localeItemInfo);
		}