Exporting to .resx files.
This commit is contained in:
Родитель
21156167f5
Коммит
f2c74441fb
|
@ -11,7 +11,8 @@ namespace MTCmd
|
|||
{
|
||||
Export,
|
||||
Import,
|
||||
Overwrite
|
||||
Overwrite,
|
||||
ExportResx
|
||||
}
|
||||
|
||||
class Program
|
||||
|
@ -49,7 +50,8 @@ namespace MTCmd
|
|||
switch (mode)
|
||||
{
|
||||
case Mode.Export:
|
||||
Export(model, exportFolder, localeId);
|
||||
case Mode.ExportResx:
|
||||
Export(mode, model, exportFolder, localeId);
|
||||
break;
|
||||
case Mode.Import:
|
||||
Import(model, importFile, false);
|
||||
|
@ -61,7 +63,7 @@ namespace MTCmd
|
|||
break;
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"{ex}");
|
||||
}
|
||||
|
@ -93,21 +95,23 @@ namespace MTCmd
|
|||
}
|
||||
}
|
||||
|
||||
static void Export(DataModel model, DirectoryInfo exportFolder, string lcid)
|
||||
static void Export(Mode mode, DataModel model, DirectoryInfo exportFolder, string lcid)
|
||||
{
|
||||
Action<string> export = (path) => { if (mode == Mode.ExportResx) model.ExportToResx(path); else model.ExportToCsv(path); };
|
||||
|
||||
if (exportFolder != null)
|
||||
{
|
||||
if(!string.IsNullOrEmpty(lcid))
|
||||
if (!string.IsNullOrEmpty(lcid))
|
||||
{
|
||||
model.DeselectAllLanguages();
|
||||
model.SetLanguageFlags(lcid, true, false);
|
||||
|
||||
model.ExportToCsv(exportFolder.FullName);
|
||||
export(exportFolder.FullName);
|
||||
Console.WriteLine(Strings.singleLocalExportSuccess, lcid, exportFolder);
|
||||
}
|
||||
else if (model.HasTargetLanguages)
|
||||
{
|
||||
model.ExportToCsv(exportFolder.FullName);
|
||||
export(exportFolder.FullName);
|
||||
Console.WriteLine(Strings.exportSuccess, exportFolder);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -16,6 +16,7 @@ using Microsoft.VisualBasic.FileIO;
|
|||
using Adomd = Microsoft.AnalysisServices.AdomdClient;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Security.Cryptography;
|
||||
using System.Resources;
|
||||
|
||||
namespace Metadata_Translator
|
||||
{
|
||||
|
@ -423,7 +424,7 @@ namespace Metadata_Translator
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Exports the translations to individual language files.
|
||||
/// Exports the translations to individual language (csv) files.
|
||||
/// The files are placed into the specified export folder.
|
||||
/// </summary>
|
||||
/// <param name="exportFolderPath"></param>
|
||||
|
@ -467,6 +468,34 @@ namespace Metadata_Translator
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Exports the translations to individual resx files.
|
||||
/// The files are placed into the specified export folder.
|
||||
/// </summary>
|
||||
/// <param name="exportFolderPath"></param>
|
||||
public void ExportToResx(string exportFolderPath)
|
||||
{
|
||||
List<ExpandoObject> dataRows = GetAllDataRows();
|
||||
if (dataRows != null && dataRows.Count > 0)
|
||||
{
|
||||
List<string> languages = SelectedLanguages.Select(l => l.LanguageTag).ToList();
|
||||
|
||||
if (languages != null && languages.Count > 0)
|
||||
{
|
||||
foreach (string lcid in languages)
|
||||
{
|
||||
using (ResXResourceWriter resx = new ResXResourceWriter(System.IO.Path.Combine(exportFolderPath, $"{lcid}.resx")))
|
||||
{
|
||||
foreach(var kvp in dataRows.GetValues(ContainerColumnHeader, lcid))
|
||||
{
|
||||
resx.AddResource(kvp.Key.ToString(), kvp.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Imports translations from a csv file. The file name must match the LCID of the target language.
|
||||
/// </summary>
|
||||
|
|
|
@ -11,10 +11,13 @@ namespace Metadata_Translator
|
|||
{
|
||||
public virtual NamedMetadataObject TabularObject { get; protected set; }
|
||||
public TranslatedProperty TranslatedProperty { get; protected set; }
|
||||
|
||||
public Guid TemporaryObjectId { get; protected set; }
|
||||
public MetadataObjectContainer(NamedMetadataObject metadataObject, TranslatedProperty translatedProperty)
|
||||
{
|
||||
TabularObject = metadataObject;
|
||||
TranslatedProperty = translatedProperty;
|
||||
TemporaryObjectId = Guid.NewGuid();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
|
|
@ -26,5 +26,30 @@ namespace Metadata_Translator
|
|||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public static Dictionary<Guid, string> GetValues(this List<ExpandoObject> collection, string containerColumnName, string columnName)
|
||||
{
|
||||
if (collection == null) return new Dictionary<Guid, string>();
|
||||
|
||||
var values = new Dictionary<Guid, string>();
|
||||
foreach (ExpandoObject row in collection)
|
||||
{
|
||||
var metaContainer = (MetadataObjectContainer)row.GetObject(containerColumnName);
|
||||
var columnValue = row.GetValue(columnName);
|
||||
|
||||
if (metaContainer != null && !string.IsNullOrEmpty(columnValue))
|
||||
{
|
||||
try
|
||||
{
|
||||
values.Add(metaContainer.TemporaryObjectId, columnValue);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception(ex.Message + " --- " + metaContainer.TemporaryObjectId.ToString() + metaContainer.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче