Exemplo n.º 1
0
 public string GetLocalizedString(LocalizedStrings key, params object[] args)
 {
     Debug.WriteLine("Looking up localized string: " + key);
     LookupToken token = new LookupToken(this);
     args = GetArgsWithToken(token, args);
     return GetLocalizedString(token, key.ToString(), args);
 }
Exemplo n.º 2
0
            static EnumExtentionCache()
            {
                var type = typeof(T);

                foreach (var field in type.GetFields(BindingFlags.Static | BindingFlags.Public))
                {
                    var name  = field.Name;
                    var value = field.GetValue(null).Cast <T>();
                    var da    = field.GetCustomAttribute <EnumDisplayNameAttribute>();
                    if (da == null || da.Value == null)
                    {
                        DisplayNames[value] = name;
                    }
                    else if (!da.Value.StartsWith("ms-resource:"))
                    {
                        DisplayNames[value] = da.Value;
                    }
                    else
                    {
                        DisplayNames[value] = LocalizedStrings.GetValue(da.Value);
                    }
                }
                dispNameCache.Add(type, DisplayNames);
            }
Exemplo n.º 3
0
        private void exportStringsToFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Find all lstring that are internalized and rewrite to 
            var plugin = GetPluginFromNode(this.PluginTree.SelectedRecord);
            if (plugin == null)
            {
                MessageBox.Show(Resources.NoPluginSelected, Resources.ErrorText);
                return;
            }

            var lstrings = new LocalizedStrings
            {
                Strings = plugin.Strings.Select(x => new LocalizedString { ID = x.Key, Type = LocalizedStringFormat.Base, Value = x.Value })
                .Union(plugin.DLStrings.Select(x => new LocalizedString { ID = x.Key, Type = LocalizedStringFormat.DL, Value = x.Value }))
                .Union(plugin.ILStrings.Select(x => new LocalizedString { ID = x.Key, Type = LocalizedStringFormat.IL, Value = x.Value }))
                .ToArray()
            };
            if ( lstrings.Strings.Length == 0 )
            {
                MessageBox.Show("No strings available to export.", Resources.ErrorText);
                return;                
            }

            using (var dlg = new System.Windows.Forms.SaveFileDialog())
            {
                if (string.IsNullOrEmpty(Properties.Settings.Default.DefaultSaveFolder)
                    || !Directory.Exists(Properties.Settings.Default.DefaultSaveFolder))
                    dlg.InitialDirectory = Path.Combine(Program.gameDataDir, "Strings");
                else
                    dlg.InitialDirectory = Path.Combine(Properties.Settings.Default.DefaultSaveFolder, "Strings");
                dlg.DefaultExt = ".xml";
                dlg.Filter = "String Table|*.xml";
                dlg.CheckPathExists = true;
                dlg.AddExtension = true;
                dlg.OverwritePrompt = true;
                dlg.FileName = string.Format("{0}_{1}.xml"
                    , Path.GetFileNameWithoutExtension(plugin.Name)
                    , Properties.Settings.Default.LocalizationName);
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    var xs = new XmlSerializer(typeof (LocalizedStrings));
                    using ( var tw = new XmlTextWriter(dlg.FileName, System.Text.Encoding.Unicode))
                    {
                        tw.Formatting = Formatting.Indented;
                        xs.Serialize(tw, lstrings);
                    }
                }
            }
        }