Пример #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);
                }
            }
        }