Skip to content

Commit eed2e01

Browse files
committed
refactor localizable text classes
1 parent b3925ba commit eed2e01

6 files changed

Lines changed: 151 additions & 269 deletions

File tree

Applications/Converter/Main/Sources/TextBase.cs

Lines changed: 0 additions & 88 deletions
This file was deleted.

Applications/Converter/Main/Sources/Text.cs renamed to Applications/Converter/Main/Sources/Texts/Text.cs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
//
1818
/* ------------------------------------------------------------------------- */
19+
using System.Threading;
20+
using Cube.Globalization;
21+
1922
namespace Cube.Pdf.Converter;
2023

2124
/* ------------------------------------------------------------------------- */
@@ -27,9 +30,10 @@ namespace Cube.Pdf.Converter;
2730
/// </summary>
2831
///
2932
/* ------------------------------------------------------------------------- */
30-
internal class Text : TextBase
33+
internal class Text() : LocalizableText(Make, new EnglishText())
3134
{
32-
// ReSharper disable InconsistentNaming
35+
#region Properties
36+
3337
#region General tab
3438
public string General_Tab => Get();
3539
public string General_Source => Get();
@@ -147,4 +151,49 @@ internal class Text : TextBase
147151
public string Filter_Tiff => Get();
148152
public string Filter_Exe => Get();
149153
#endregion
154+
155+
#endregion
156+
157+
#region Methods
158+
159+
/* --------------------------------------------------------------------- */
160+
///
161+
/// Make
162+
///
163+
/// <summary>
164+
/// Makes a text group with the specified Language value.
165+
/// </summary>
166+
///
167+
/* --------------------------------------------------------------------- */
168+
private static TextGroup Make(Language src) => src switch
169+
{
170+
Language.Auto => Make(Locale.GetDefaultLanguage()),
171+
Language.English => new EnglishText(),
172+
Language.German => new GermanText(),
173+
Language.Japanese => new JapaneseText(),
174+
Language.Russian => new RussianText(),
175+
Language.SimplifiedChinese => new SimplifiedChineseText(),
176+
_ => default,
177+
};
178+
179+
/* --------------------------------------------------------------------- */
180+
///
181+
/// OnReset
182+
///
183+
/// <summary>
184+
/// Occurs when the Reset method is invoked.
185+
/// </summary>
186+
///
187+
/* --------------------------------------------------------------------- */
188+
protected override void OnReset(Language src)
189+
{
190+
base.OnReset(src);
191+
192+
var ci = src.ToCultureInfo();
193+
Thread.CurrentThread.CurrentCulture = ci;
194+
Thread.CurrentThread.CurrentUICulture = ci;
195+
Properties.Resources.Culture = ci;
196+
}
197+
198+
#endregion
150199
}

Applications/Editor/Main/Sources/Models/TextBase.cs

Lines changed: 0 additions & 87 deletions
This file was deleted.

Applications/Editor/Main/Sources/Models/Text.cs renamed to Applications/Editor/Main/Sources/Texts/Text.cs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
//
1818
/* ------------------------------------------------------------------------- */
19+
using System.Threading;
20+
using Cube.Globalization;
21+
1922
namespace Cube.Pdf.Editor;
2023

2124
/* ------------------------------------------------------------------------- */
@@ -27,9 +30,10 @@ namespace Cube.Pdf.Editor;
2730
/// </summary>
2831
///
2932
/* ------------------------------------------------------------------------- */
30-
internal class Text : TextBase
33+
internal class Text() : LocalizableText(Make, new EnglishText())
3134
{
32-
// ReSharper disable InconsistentNaming
35+
#region Properties
36+
3337
#region Menus
3438
public string Menu_Ok => Get();
3539
public string Menu_Cancel => Get();
@@ -213,4 +217,47 @@ internal class Text : TextBase
213217
public string Filter_Extractable => Get();
214218
public string Filter_Pdf => Get();
215219
#endregion
220+
221+
#endregion
222+
223+
#region Methods
224+
225+
/* --------------------------------------------------------------------- */
226+
///
227+
/// Make
228+
///
229+
/// <summary>
230+
/// Makes a text group with the specified Language value.
231+
/// </summary>
232+
///
233+
/* --------------------------------------------------------------------- */
234+
private static TextGroup Make(Language src) => src switch
235+
{
236+
Language.Auto => Make(Locale.GetDefaultLanguage()),
237+
Language.English => new EnglishText(),
238+
Language.German => new GermanText(),
239+
Language.Japanese => new JapaneseText(),
240+
Language.Russian => new RussianText(),
241+
Language.SimplifiedChinese => new SimplifiedChineseText(),
242+
_ => default,
243+
};
244+
245+
/* --------------------------------------------------------------------- */
246+
///
247+
/// OnReset
248+
///
249+
/// <summary>
250+
/// Occurs when the Reset method is invoked.
251+
/// </summary>
252+
///
253+
/* --------------------------------------------------------------------- */
254+
protected override void OnReset(Language src)
255+
{
256+
base.OnReset(src);
257+
var ci = src.ToCultureInfo();
258+
Thread.CurrentThread.CurrentCulture = ci;
259+
Thread.CurrentThread.CurrentUICulture = ci;
260+
}
261+
262+
#endregion
216263
}

0 commit comments

Comments
 (0)