-
Notifications
You must be signed in to change notification settings - Fork 0
/
TranslationHelper.cs
75 lines (64 loc) · 3.66 KB
/
TranslationHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using AMO = Microsoft.AnalysisServices;
using TOM = Microsoft.AnalysisServices.Tabular;
namespace TOM2AMO
{
public static class TranslationHelper
{
public static int GetLCIDFromCultureName(string Name)
{
return new System.Globalization.CultureInfo(Name).LCID;
}
public static string GetCultureNameFromLCID(int LCID)
{
return new System.Globalization.CultureInfo(LCID).Name;
}
public static AMO.Translation GetTranslation(TOM.Culture TOMCulture, TOM.MetadataObject TOMObject)
{
AMO.Translation AMOTranslation = new AMO.Translation
{
Language = GetLCIDFromCultureName(TOMCulture.Name)
};
//Caption (i.e. Name)
if (TOMCulture.ObjectTranslations[TOMObject, TOM.TranslatedProperty.Caption] != null)
AMOTranslation.Caption = TOMCulture.ObjectTranslations[TOMObject, TOM.TranslatedProperty.Caption].Value;
//Description
if (TOMCulture.ObjectTranslations[TOMObject, TOM.TranslatedProperty.Description] != null)
AMOTranslation.Description = TOMCulture.ObjectTranslations[TOMObject, TOM.TranslatedProperty.Description].Value;
//Display Folder
if (TOMCulture.ObjectTranslations[TOMObject, TOM.TranslatedProperty.DisplayFolder] != null)
AMOTranslation.DisplayFolder = TOMCulture.ObjectTranslations[TOMObject, TOM.TranslatedProperty.DisplayFolder].Value;
// If translation has no properties, it does not exist.
// As such, return null unless it has at least one valid property
if (AMOTranslation.Caption != null || AMOTranslation.Description != null || AMOTranslation.DisplayFolder != null)
return AMOTranslation;
else
return null;
}
/// <summary>
/// Adds a translation for the TOM object based on the supplied AMOTranslation.
/// Creates the relevant culture if it does not exist.
/// </summary>
/// <param name="TOMDatabase">The TOM Database to add the Translation to</param>
/// <param name="TOMObject">The TOM Object the translation is being added for</param>
/// <param name="AMOTranslation">The AMO Translation being transferred to the TOM Database</param>
public static void AddTOMTranslation(TOM.Database TOMDatabase, TOM.MetadataObject TOMObject, AMO.Translation AMOTranslation)
{
string CultureName = TranslationHelper.GetCultureNameFromLCID(AMOTranslation.Language);
//Add Culture if it does not exist
if (!TOMDatabase.Model.Cultures.ContainsName(CultureName))
TOMDatabase.Model.Cultures.Add(new TOM.Culture { Name = CultureName });
//Get existing culture
TOM.Culture TOMCulture = TOMDatabase.Model.Cultures.Find(CultureName);
//Add the various translated properties to the translation
TOMCulture.ObjectTranslations.Add(
new TOM.ObjectTranslation { Object = TOMObject, Property = TOM.TranslatedProperty.Caption, Value = AMOTranslation.Caption }
);
TOMCulture.ObjectTranslations.Add(
new TOM.ObjectTranslation { Object = TOMObject, Property = TOM.TranslatedProperty.Description, Value = AMOTranslation.Description }
);
TOMCulture.ObjectTranslations.Add(
new TOM.ObjectTranslation { Object = TOMObject, Property = TOM.TranslatedProperty.DisplayFolder, Value = AMOTranslation.DisplayFolder }
);
}
}
}