Support word group translations

This commit is contained in:
~lucidiot 2022-06-19 04:58:20 +02:00
parent f6ef16168c
commit 319f241939
7 changed files with 171 additions and 22 deletions

View File

@ -10,13 +10,24 @@ namespace ToeCracker {
InitializeComponent();
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
/// <summary>
/// Create a new tab page in the form's TabControl to represent a list of words returned in a query.
/// </summary>
/// <param name="title">Title of the tab page.</param>
/// <param name="words">List of words to display.</param>
private void CreateTab(string title, string[] words) {
// TODO: Support translating the title automatically
if (Thesaurus.Translations.ContainsKey(title))
title = Thesaurus.Translations[title];
TabPage page = new TabPage(title);
ListBox listBox = new ListBox();
listBox.Items.AddRange(words);
@ -89,6 +100,7 @@ namespace ToeCracker {
}
private void wordContextMenuStrip_Opening(object sender, CancelEventArgs e) {
// Disable the context menu items when the user right-clicks but no word was selected
this.copyToolStripMenuItem.Enabled = this.SelectedWord != null;
this.lookUpToolStripMenuItem.Enabled = this.SelectedWord != null;
}

View File

@ -222,8 +222,8 @@
<data name="searchButton.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlzAAALDgAA
Cw4BQL7hQQAAAnxJREFUOE+Vk9tLYlEUxk2SwjApuxzFEjsVaJdjRGU3LEOxEiOTICOpJCwK7GGosZm0
YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAlwSFlzAAALCgAA
CwoBv0NmUwAAAnxJREFUOE+Vk9tLYlEUxk2SwjApuxzFEjsVaJdjRGU3LEOxEiOTICOpJCwK7GGosZm0
maGXsIeYmi5UlsfSrmrZBZqBeep13oaZp/6Ubzr75eSbs2HBfljfb629vrUFAJjXeHmN/z2chhFw4uSf
JBaeFuC59WD0ahSOMwcGogPoi/Sh/6QfZtYMw5EB7YftaNhpAB2ksfa0xhV84QBYfFrEwa8DBJ+D8H33
Yf5xHjOpGUzdTGEyMYmx6zEMXwzDFrWh+7gbzCYD+aKcdEwAs3ezWH9ex8rPFXgfvPDceDB+PY7U3xRJ

View File

@ -1,16 +0,0 @@
using System;
using System.Windows.Forms;
namespace ToeCracker {
static class Program {
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
}

View File

@ -59,5 +59,95 @@ namespace ToeCracker.Properties {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to adjective.
/// </summary>
internal static string Adjective {
get {
return ResourceManager.GetString("Adjective", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to adverb.
/// </summary>
internal static string Adverb {
get {
return ResourceManager.GetString("Adverb", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to noun.
/// </summary>
internal static string Noun {
get {
return ResourceManager.GetString("Noun", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to An error occurred while parsing data from the thesaurus:.
/// </summary>
internal static string ParsingError {
get {
return ResourceManager.GetString("ParsingError", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to XML parsing error.
/// </summary>
internal static string ParsingErrorTitle {
get {
return ResourceManager.GetString("ParsingErrorTitle", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to An error occurred while fetching data from the thesaurus:.
/// </summary>
internal static string RequestError {
get {
return ResourceManager.GetString("RequestError", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to HTTP request error.
/// </summary>
internal static string RequestErrorTitle {
get {
return ResourceManager.GetString("RequestErrorTitle", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to rhymes with.
/// </summary>
internal static string RhymesWith {
get {
return ResourceManager.GetString("RhymesWith", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to sounds kind of like.
/// </summary>
internal static string SoundsLike {
get {
return ResourceManager.GetString("SoundsLike", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to verb.
/// </summary>
internal static string Verb {
get {
return ResourceManager.GetString("Verb", resourceCulture);
}
}
}
}

View File

@ -117,4 +117,44 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Adjective" xml:space="preserve">
<value>adjective</value>
<comment>Word group for synonyms of an adjective.</comment>
</data>
<data name="Adverb" xml:space="preserve">
<value>adverb</value>
<comment>Word group for synonyms of an adverb.</comment>
</data>
<data name="Noun" xml:space="preserve">
<value>noun</value>
<comment>Word group for synonyms of a noun.</comment>
</data>
<data name="ParsingError" xml:space="preserve">
<value>An error occurred while parsing data from the thesaurus:</value>
<comment>Error message shown when the HTML structure could not be understood. Further details are given below this message.</comment>
</data>
<data name="ParsingErrorTitle" xml:space="preserve">
<value>XML parsing error</value>
<comment>Title of the dialog box where the parsing error is shown.</comment>
</data>
<data name="RequestError" xml:space="preserve">
<value>An error occurred while fetching data from the thesaurus:</value>
<comment>Error message shown when an HTTP request fails. Further details are given below this message.</comment>
</data>
<data name="RequestErrorTitle" xml:space="preserve">
<value>HTTP request error</value>
<comment>Title of the dialog box where the request error is shown.</comment>
</data>
<data name="RhymesWith" xml:space="preserve">
<value>rhymes with</value>
<comment>Word group for words that rhyme with this word.</comment>
</data>
<data name="SoundsLike" xml:space="preserve">
<value>sounds kind of like</value>
<comment>Word group for words that "sound kind of like" this word.</comment>
</data>
<data name="Verb" xml:space="preserve">
<value>verb</value>
<comment>Word group for synonyms of a verb.</comment>
</data>
</root>

View File

@ -14,6 +14,24 @@ namespace ToeCracker {
private const string RESULT_HEADER = "<div class=\"results\">";
private const string RESULT_FOOTER = "</div>";
/// <summary>
/// A dictionary mapping English word group keys with translated values.
/// Some keys might be missing, in which case they should be displayed as they are;
/// you might want to open an issue to request those translations to be added.
/// </summary>
public static Dictionary<string, string> Translations {
get {
Dictionary<string, string> tr = new Dictionary<string, string>();
tr["adjective"] = Properties.Resources.Adjective;
tr["adverb"] = Properties.Resources.Verb;
tr["noun"] = Properties.Resources.Noun;
tr["sounds kind of like"] = Properties.Resources.SoundsLike;
tr["rhymes with"] = Properties.Resources.RhymesWith;
tr["verb"] = Properties.Resources.Verb;
return tr;
}
}
private static Uri BuildURI(string query) {
return new Uri(String.Format(Properties.Settings.Default.BaseURL, query), UriKind.Absolute);
}

View File

@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ToeCracker</RootNamespace>
<AssemblyName>ToeCracker</AssemblyName>
<StartupObject>ToeCracker.Program</StartupObject>
<StartupObject>ToeCracker.MainForm</StartupObject>
<ApplicationIcon>icon.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@ -44,13 +44,18 @@
<Compile Include="MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="ConcatenatedStream.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="MainForm.fr.resx">
<DependentUpon>MainForm.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="MainForm.resx">
<SubType>Designer</SubType>
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.fr.resx">
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>