Skip to content

Commit

Permalink
Merge pull request #154 from MicrosoftTranslator/AvalableLanguages
Browse files Browse the repository at this point in the history
Available languages
  • Loading branch information
chriswendt1 authored Apr 12, 2021
2 parents 47579b6 + 2b8d5bc commit 078ae91
Show file tree
Hide file tree
Showing 20 changed files with 215 additions and 1,122 deletions.
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ TranslationAssistant.DocumentTranslationInterface/bin/Release/FileTranslator.vsh
*.ide
*.ide-shm
*.ide
.vs/Microsoft.DocumentTranslator/v15/sqlite3/storage.ide
*.ide-wal
.vs/Microsoft.DocumentTranslator/v15/sqlite3/storage.ide
*.ide
*.sqlite
/TranslationAssistant.DocumentTranslationInstaller/obj/Debug
*.dtbcache
/TranslationAssistant.AutomationToolkit.BasePlugin/bin/Debug/TranslationAssistant.AutomationToolkit.BasePlugin.dll
Expand All @@ -43,6 +42,5 @@ TranslationAssistant.DocumentTranslationInterface/bin/Release/FileTranslator.vsh
/TranslationAssistant.AutomationToolkit.TranslationPlugins/obj/Release
/azure-libraries-for-net
/OpenXmlPowerTools/bin/Debug
/.vs/Microsoft.DocumentTranslator/DesignTimeBuild
/.vs/
.vs/
.vs/slnx.sqlite
974 changes: 0 additions & 974 deletions .vs/Microsoft.DocumentTranslator/config/applicationhost.config

This file was deleted.

6 changes: 0 additions & 6 deletions .vs/VSWorkspaceState.json

This file was deleted.

Binary file removed .vs/slnx.sqlite
Binary file not shown.
4 changes: 2 additions & 2 deletions Microsoft.DocumentTranslator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29609.76
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocumentTranslator", "TranslationAssistant.DocumentTranslationInterface\DocumentTranslator.csproj", "{4007B1E0-9E4F-449A-AE61-C38F771001F6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TranslationServices.Core", "TranslationServices.Core\TranslationServices.Core.csproj", "{9F027538-F794-4543-A510-155043A40CC6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TranslationAssistant.Business", "TranslationAssistant.Business\TranslationAssistant.Business.csproj", "{6BF8556D-3875-4C4A-86B4-A9AA5B1F8696}"
ProjectSection(ProjectDependencies) = postProject
{1E89FBEE-7C28-41F8-8894-1B11D4855A26} = {1E89FBEE-7C28-41F8-8894-1B11D4855A26}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocumentTranslator", "TranslationAssistant.DocumentTranslationInterface\DocumentTranslator.csproj", "{4007B1E0-9E4F-449A-AE61-C38F771001F6}"
EndProject
Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "TranslationAssistant.DocumentTranslationInstaller", "TranslationAssistant.DocumentTranslationInstaller\TranslationAssistant.DocumentTranslationInstaller.wixproj", "{CB4E5694-FB0B-4E8C-92EB-FEB5362A28E8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TranslationAssistant.AutomationToolkit.BasePlugin", "TranslationAssistant.AutomationToolkit.BasePlugin\TranslationAssistant.AutomationToolkit.BasePlugin.csproj", "{443BE96F-82E7-4952-A078-DEBCFF6B2311}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ public TranslateDocuments(ConsoleLogger Logger)
"from",
false,
new[] { "Auto-Detect" },
TranslationServiceFacade.AvailableLanguages.Keys.ToArray(),
AvailableLanguages.GetLanguages().Result.Keys.ToArray(),
true,
"The source language. Auto-detect if no language specified.");

this.targetLanguages = new SimpleStringArgument(
"to",
true,
new string[] { },
TranslationServiceFacade.AvailableLanguages.Keys.ToArray(),
AvailableLanguages.GetLanguages().Result.Keys.ToArray(),
new[] { ',' },
"The target language code, or comma-separated list of language codes.");

Expand Down Expand Up @@ -185,8 +185,7 @@ public override bool Execute()
var sourceLanguageExpanded = String.IsNullOrEmpty(this.sourceLanguage.ValueString)
|| this.sourceLanguage.ValueString.Equals("Auto-Detect")
? "Auto-Detect"
: TranslationServiceFacade.AvailableLanguages[
this.sourceLanguage.ValueString];
: AvailableLanguages.GetLanguages().Result[this.sourceLanguage.ValueString];
string languagename = TranslationServiceFacade.LanguageCodeToLanguageName(language.ToString());

DocumentTranslationManager.DoTranslation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ public TranslateXML (ConsoleLogger Logger)
"from",
false,
new[] { "Auto-Detect" },
TranslationServiceFacade.AvailableLanguages.Keys.ToArray(),
AvailableLanguages.GetLanguages().Result.Keys.ToArray(),
true,
"The source language. Auto-detect if no language specified.");

this.tolanguage = new SimpleStringArgument(
"to",
true,
new string[] { },
TranslationServiceFacade.AvailableLanguages.Keys.ToArray(),
AvailableLanguages.GetLanguages().Result.Keys.ToArray(),
new[] { ',' },
"The target language code, or comma-separated list of language codes.");

Expand Down
9 changes: 3 additions & 6 deletions TranslationAssistant.Business/AllLanguageList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,15 @@ public static class AllLanguageList

public static async Task<string> GetAllLanguages()
{
Task GetLanguagesTask = TranslationServiceFacade.GetLanguages();
StringWriter writer = new StringWriter();
Dictionary<string, string> languagelist = new Dictionary<string, string>();
await GetLanguagesTask;
languagelist = TranslationServiceFacade.AvailableLanguages;
languagelist = await AvailableLanguages.GetLanguages();
writer.WriteLine("{0}\t{1}\t{2}", "Language", "Language Code", "Display Name");
writer.WriteLine("------------------------------------------------------");
foreach (KeyValuePair<string, string> language in languagelist.ToList())
{
Task t = TranslationServiceFacade.GetLanguages(language.Key);
await t;
foreach (KeyValuePair<string, string> lang in TranslationServiceFacade.AvailableLanguages)
Dictionary<string, string> languagesinlanguage = await AvailableLanguages.GetLanguages(language.Key);
foreach (KeyValuePair<string, string> lang in languagesinlanguage)
{
writer.WriteLine("{0}\t{1}\t{2}", language.Key, lang.Key, lang.Value);
}
Expand Down
2 changes: 1 addition & 1 deletion TranslationAssistant.Business/TranslateFromAll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private async Task<SortedDictionary<string, string>> TranslateFromAllLanguages(s
{
EventHandler handler = OneTranslationDone;
List<Task<KeyValuePair<string, string>>> tasklist = new List<Task<KeyValuePair<string, string>>>();
foreach (KeyValuePair<string, string> language in TranslationServiceFacade.AvailableLanguages)
foreach (KeyValuePair<string, string> language in await AvailableLanguages.GetLanguages())
{
Task<KeyValuePair<string, string>> task = TranslateInternal(text, language.Key, to, category, contentType);
tasklist.Add(task);
Expand Down
2 changes: 1 addition & 1 deletion TranslationAssistant.Business/TranslateToAll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private async Task<SortedDictionary<string, string>> TranslateToAllLanguages(str
{
EventHandler handler = OneTranslationDone;
List<Task<KeyValuePair<string, string>>> tasklist = new List<Task<KeyValuePair<string, string>>>();
foreach (KeyValuePair<string, string> language in TranslationServiceFacade.AvailableLanguages)
foreach (KeyValuePair<string, string> language in await AvailableLanguages.GetLanguages())
{
Task<KeyValuePair<string, string>> task = TranslateInternal(text, from, language.Key, category, contentType);
tasklist.Add(task);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ private void PasswordBox_PasswordChanged(object sender, System.Windows.RoutedEve

private void CheckBox_Click(object sender, System.Windows.RoutedEventArgs e)
{
_ = TranslationServices.Core.TranslationServiceFacade.Initialize(true);
TranslationServices.Core.AvailableLanguages.ShowExperimental = ShowExperimental_CheckBox.IsChecked.Value;
_ = TranslationServices.Core.AvailableLanguages.GetLanguages();
ShowExperimental_Changed?.Invoke(this, EventArgs.Empty);
}
private void CloudSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ namespace TranslationAssistant.DocumentTranslationInterface.Pages

#endregion

/// <summary>
/// <summary>
/// Interaction logic for ProjectCodeCommentsTranslationPage.xaml
/// </summary>
public partial class DocumentTranslationPage : UserControl
{
#region Constructors and Destructors
readonly ViewModel.DocumentTranslation documentTranslation = new ViewModel.DocumentTranslation();

/// <summary>
/// Initializes a new instance of the <see cref="DocumentTranslationPage" /> class.
Expand Down Expand Up @@ -62,6 +63,7 @@ private void DocumentTranslationPage_KeyDown(object sender, System.Windows.Input

private void RefreshLanguageComboBoxes(bool successful)
{
documentTranslation.PopulateAvailableLanguages();
cbSourceLanguages.Items.Refresh();
cbTargetLanguages.Items.Refresh();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace TranslationAssistant.DocumentTranslationInterface.Pages
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using TranslationAssistant.DocumentTranslationInterface.Common;

/// <summary>
/// Interaction logic for ProjectCodeCommentsTranslationPage.xaml
Expand All @@ -37,18 +38,26 @@ public partial class ImmediateWindow : UserControl
/// </summary>
public ImmediateWindow()
{
Debug.WriteLine("ImmediateWindow entered.");
this.InitializeComponent();
this.Loaded += ImmediateWindow_Loaded;
this.GotFocus += ImmediateWindow_GotFocus;
TranslationServices.Core.AvailableLanguages.OnUpdate += AvailableLanguages_OnUpdate;
SingletonEventAggregator.Instance.GetEvent<AccountValidationEvent>().Unsubscribe(RefreshLanguageComboBoxes);
SingletonEventAggregator.Instance.GetEvent<AccountValidationEvent>().Subscribe(RefreshLanguageComboBoxes);
}

private void ImmediateWindow_GotFocus(object sender, RoutedEventArgs e)
private void RefreshLanguageComboBoxes(bool successful)
{
documentTranslation.PopulateAvailableLanguages();
cbSourceLanguages.Items.Refresh();
cbTargetLanguages.Items.Refresh();
}

private void AvailableLanguages_OnUpdate(object sender, EventArgs e)
{
Debug.WriteLine("ImmediateWindow.xaml.cs: Available Languages: {0}", TranslationServices.Core.TranslationServiceFacade.AvailableLanguages.Count);
documentTranslation.PopulateAvailableLanguages();
cbSourceLanguages.GetBindingExpression(ComboBox.ItemsSourceProperty).UpdateTarget();
cbTargetLanguages.GetBindingExpression(ComboBox.ItemsSourceProperty).UpdateTarget();

}

private void ImmediateWindow_Loaded(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -181,6 +190,7 @@ private void CbSourceLanguages_SelectionChanged(object sender, SelectionChangedE
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
documentTranslation.SaveSettings();
TranslationServices.Core.AvailableLanguages.OnUpdate -= AvailableLanguages_OnUpdate;
}

private void CbTranslateMode_SelectionChanged(object sender, SelectionChangedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public AccountViewModel()
this.AzureCloud = TranslationServices.Core.TranslationServiceFacade.AzureCloud;
this.useCustomEndpoint = TranslationServices.Core.TranslationServiceFacade.UseCustomEndpoint;
this.customEndpointUrl = TranslationServices.Core.TranslationServiceFacade.CustomEndpointUrl;
this.showExperimental = TranslationServices.Core.TranslationServiceFacade.ShowExperimental;
this.showExperimental = TranslationServices.Core.AvailableLanguages.ShowExperimental;
}

/// <summary>
Expand All @@ -279,12 +279,12 @@ private async void SaveAccountClick()
TranslationServices.Core.TranslationServiceFacade.AzureRegion = this.azureRegion;
TranslationServices.Core.TranslationServiceFacade.UseCustomEndpoint = this.useCustomEndpoint;
TranslationServices.Core.TranslationServiceFacade.CustomEndpointUrl = this.customEndpointUrl;
TranslationServices.Core.TranslationServiceFacade.ShowExperimental = this.showExperimental;
TranslationServices.Core.AvailableLanguages.ShowExperimental = this.showExperimental;
TranslationServices.Core.AvailableLanguages.ShowExperimental = this.showExperimental;
TranslationServices.Core.TranslationServiceFacade.SaveCredentials();
_ = TranslationServices.Core.TranslationServiceFacade.Initialize(true);

bool isready = false;

bool isready;
try { isready = await TranslationServices.Core.TranslationServiceFacade.IsTranslationServiceReadyAsync(); }
catch { isready = false; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public DocumentTranslation()
_ = TranslationServiceFacade.Initialize();
this.PopulateAvailableLanguages();
this.PopulateTranslateMode();
AvailableLanguages.OnUpdate += AvailableLanguages_OnUpdate;
this.ShowProgressBar = false;
this.IsGoButtonEnabled = false;
this.TargetFolder = string.Empty;
Expand All @@ -137,6 +138,11 @@ public DocumentTranslation()
SingletonEventAggregator.Instance.GetEvent<AccountValidationEvent>().Subscribe(PopulateReadyToTranslateMessage);
}

private void AvailableLanguages_OnUpdate(object sender, EventArgs e)
{
PopulateAvailableLanguages();
}

/// <summary>
/// Save the selected source and target languages for the next session;
/// </summary>
Expand Down Expand Up @@ -526,10 +532,7 @@ public void PopulateAvailableLanguages()
if (!TranslationServiceFacade.UseCustomEndpoint) this.sourceLanguageList.Add(Properties.Resources.Common_AutoDetect);
try
{
lock (TranslationServiceFacade.AvailableLanguages)
{
this.targetLanguageList.AddRange(TranslationServiceFacade.AvailableLanguages.Values);
}
targetLanguageList.AddRange(AvailableLanguages.GetLanguages().Result.Values);
}
catch (Exception ex) {
this.StatusText = String.Format("{0}\n{1}", Properties.Resources.Error_LanguageList, ex.Message);
Expand Down
Loading

0 comments on commit 078ae91

Please sign in to comment.