1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- using FastReport.Utils;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- namespace FastReport.Web
- {
- internal class WebRes
- {
- private string category;
- private const string badResult = "NOT LOCALIZED!";
- private XmlDocument locale;
- private static readonly XmlDocument builtinLocale;
- public void LoadLocale(string fileName)
- {
- if (File.Exists(fileName))
- {
- locale = new XmlDocument();
- locale.Load(fileName);
- }
- else
- locale = builtinLocale;
- }
- public void LoadLocale(Stream stream)
- {
- locale = new XmlDocument();
- locale.Load(stream);
- }
- public string Get(string id)
- {
- if (!String.IsNullOrEmpty(category))
- {
- return InternalGet(category + "," + id);
- }
- else
- return InternalGet(id);
- }
- private string InternalGet(string id)
- {
- string result = Get(id, locale);
- // if no item found, try built-in (english) locale
- if (string.IsNullOrEmpty(result))
- {
- if (locale != builtinLocale)
- result = Get(id, builtinLocale);
- if (string.IsNullOrEmpty(result))
- result = id + " " + badResult;
- }
- return result;
- }
- private string Get(string id, XmlDocument locale)
- {
- string[] categories = id.Split(',');
- XmlItem xi = locale.Root;
- int i;
- foreach (string category in categories)
- {
- i = xi.Find(category);
- if (i == -1)
- return null;
- xi = xi[i];
- }
- return xi.GetProp("Text");
- }
- public void Root(string Section)
- {
- category = Section;
- }
- public WebRes(string Section = "")
- {
- locale = builtinLocale;
- Root(Section);
- }
- static WebRes()
- {
- builtinLocale = new XmlDocument();
- using (Stream stream = ResourceLoader.GetStream("en.xml"))
- {
- builtinLocale.Load(stream);
- }
- }
- }
- }
|