Exemplo n.º 1
0
        LocalizationData ReadAssemblyLocalization(String assemblyName)
        {
            var xmlPath = GetXmlFilePath(assemblyName);

            if (System.IO.File.Exists(xmlPath))
            {
                try
                {
                    using (var fs = new FileStream(xmlPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        using (var xr = new XmlTextReader(fs))
                        {
                            var data = LocalizationData.ReadXml(xr);
                            Logger.InfoFormat("Localization '{1}' for assembly '{0}' successfully loaded.", assemblyName, LangCode);
                            return(data);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Exception("Read Xml localization data error.", ex);
                }
            }
            return(new LocalizationData());
        }
 public EmbeddedXmlLocalizationStore(String langCode)
 {
     LangCode         = langCode;
     cache            = new Dictionary <Type, object>();
     loadedAssemblies = new HashSet <Assembly>();
     localizationData = new LocalizationData();
 }
        public LocalizationData GetLocalizationData(Assembly assembly)
        {
            var embeddedPath = String.Format(@"Localization\{0}.xml", LangCode);

            try
            {
                using (var fs = AssemblyHelper.ReadEmbeddedFile(assembly, embeddedPath))
                {
                    if (fs == null)
                    {
                        return(new LocalizationData());
                    }
                    using (var xr = new XmlTextReader(fs))
                    {
                        var data = LocalizationData.ReadXml(xr);
                        Debug.WriteLine("Embedded Localization '{1}' for assembly '{0}' successfully loaded.", assembly, LangCode);
                        return(data);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Read Xml localization data error: {0}", ex);
            }
            return(new LocalizationData());
        }
Exemplo n.º 4
0
 public void SetLocalizationData(String assemblyName, LocalizationData data)
 {
     using (var xw = new XmlTextWriter(GetXmlFilePath(assemblyName), Encoding.UTF8))
     {
         xw.Formatting = Formatting.Indented;
         data.WriteXml(xw);
     }
 }
Exemplo n.º 5
0
 public XmlLocalizationStore(String langCode, String path, IEnumerable <ILocalizationDataProvider> providers)
 {
     Path             = path;
     LangCode         = langCode;
     cache            = new Dictionary <Type, object>();
     loadedAssemblies = new HashSet <string>();
     localizationData = new LocalizationData();
     this.providers   = providers;
 }
Exemplo n.º 6
0
 public static LocalizationData GetDefaultLocalizationData(Assembly assembly, IEnumerable<ILocalizationDataProvider> providers)
 {
     LocalizationData res = new LocalizationData();
     foreach (var p in providers)
     {
         var data = p.ReadDefaultData(assembly);
         res.Include(data);
     }
     return res;
 }
Exemplo n.º 7
0
        public static LocalizationData GetDefaultLocalizationData(Assembly assembly, IEnumerable <ILocalizationDataProvider> providers)
        {
            LocalizationData res = new LocalizationData();

            foreach (var p in providers)
            {
                var data = p.ReadDefaultData(assembly);
                res.Include(data);
            }
            return(res);
        }
Exemplo n.º 8
0
 public void Override(LocalizationData d)
 {
     foreach (var od in d.Data)
     {
         Field[] data;
         if (Data.TryGetValue(od.Key, out data))
         {
             foreach (var f in data)
                 foreach (var nf in od.Value)
                     if (f.FieldName == nf.FieldName)
                         f.LocalizedText = nf.LocalizedText;
         }
     }
 }
Exemplo n.º 9
0
 public void Override(LocalizationData d)
 {
     foreach (var od in d.Data)
     {
         Field[] data;
         if (Data.TryGetValue(od.Key, out data))
         {
             foreach (var f in data)
             {
                 foreach (var nf in od.Value)
                 {
                     if (f.FieldName == nf.FieldName)
                     {
                         f.LocalizedText = nf.LocalizedText;
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 10
0
 public void Include(LocalizationData d)
 {
     Include(d.Data);
 }
Exemplo n.º 11
0
 public void Include(LocalizationData d)
 {
     Include(d.Data);
 }