Skip to content

Commit

Permalink
Language setting additional logic wrapped in API method.
Browse files Browse the repository at this point in the history
Now changing current culture, setting message boxes reading direction, and saving language to database is done through one method only.
  • Loading branch information
Ambratolm authored and Ambratolm committed Aug 9, 2021
1 parent 48f527c commit b66ed5a
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 28 deletions.
Binary file modified GestionClient/GestionClient.suo
Binary file not shown.
35 changes: 31 additions & 4 deletions GestionClient/GestionClient/API/Core/Language.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ namespace GestionClient
{
static class Language
{
public static ResourceManager LanguagesResourceManager = new ResourceManager("GestionClient.Languages.Res", typeof(Form_Main).Assembly);
public static CultureInfo CurrentCulture = CultureInfo.CreateSpecificCulture("fr");
private const string _languageResourceFileName = "GestionClient.Languages.Res";
private static ResourceManager _languagesResourceManager = new ResourceManager(_languageResourceFileName, typeof(Form_Main).Assembly);
private static CultureInfo _currentCulture = CultureInfo.CreateSpecificCulture("fr");

public static MessageBoxOptions CurrentMessageBoxOptions = new MessageBoxOptions();

public static bool IsArabic
Expand All @@ -18,6 +20,29 @@ public static bool IsArabic
}
}

#region Private-Methods
/// <summary>
/// Set values indicating whether the text is displayed right to left.
/// </summary>
private static void SetMessageBoxesReadingDirection()
{
if (_currentCulture.TextInfo.IsRightToLeft)
{
Language.CurrentMessageBoxOptions = MessageBoxOptions.RightAlign
| MessageBoxOptions.RtlReading;
MessageBoxManager.Yes = Language.GetString("MessageBox_YES");
MessageBoxManager.No = Language.GetString("MessageBox_NO");
MessageBoxManager.Register();

}
else
{
Language.CurrentMessageBoxOptions = new MessageBoxOptions();
MessageBoxManager.Unregister();
}
}
#endregion

/// <summary>
/// Retourne la langue actuelle.
/// </summary>
Expand All @@ -29,11 +54,13 @@ public static string GetCurrentLanguage()
}

/// <summary>
/// Enregistre la langue actuelle dans la base de données.
/// Change et enregistre la langue actuelle dans la base de données.
/// </summary>
/// <param name="language"></param>
public static void SetCurrentLanguage(string language)
{
_currentCulture = CultureInfo.CreateSpecificCulture(language);
SetMessageBoxesReadingDirection();
Database.MainDataSet.Tables["Langue"].Rows[0]["abrv"] = language;
Database.ApplyChanges(Database.LangueDataAdapter, "Langue");
}
Expand All @@ -48,7 +75,7 @@ public static void SetCurrentLanguage(string language)
/// </returns>
public static string GetString(string name)
{
return LanguagesResourceManager.GetString(name, CurrentCulture);
return _languagesResourceManager.GetString(name, _currentCulture);
}
}
}
26 changes: 2 additions & 24 deletions GestionClient/GestionClient/GUI/Form_Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,23 +221,13 @@ private void menuItem_french_Click(object sender, EventArgs e)
{
try
{
if (menuItem_french.Checked == false)
if (!menuItem_french.Checked)
{
menuItem_french.Checked = true;
menuItem_arabic.Checked = false;
// changement de la langue au français
Language.CurrentCulture = CultureInfo.CreateSpecificCulture("fr");
// enregistrement de la langue actuelle
Language.SetCurrentLanguage("fr");
// messagesBox => état normal
Language.CurrentMessageBoxOptions = new MessageBoxOptions();
// QuickMessageBox buttons text => état normal
MessageBoxManager.Unregister();
// main form => état normal
this.RightToLeft = RightToLeft.No;
// modification du texte des controls
SwitchLanguage();
// on informe les fenêtres enfants
this.OnLanguageChanged(sender, e);
}
}
Expand All @@ -251,25 +241,13 @@ private void menuItem_arabic_Click(object sender, EventArgs e)
{
try
{
if (menuItem_arabic.Checked == false)
if (!menuItem_arabic.Checked)
{
menuItem_french.Checked = false;
menuItem_arabic.Checked = true;
// changement de la langue à l'arabe
Language.CurrentCulture = CultureInfo.CreateSpecificCulture("ar");
// enregistrement de la langue actuelle
Language.SetCurrentLanguage("ar");
// messagesBox => RightToLeft
Language.CurrentMessageBoxOptions = MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading;
// messagesBox buttons text
MessageBoxManager.Yes = Language.GetString("MessageBox_YES");
MessageBoxManager.No = Language.GetString("MessageBox_NO");
MessageBoxManager.Register();
// main form => RightToLeft
this.RightToLeft = RightToLeft.Yes;
// modification du texte des controls
SwitchLanguage();
// on informe les fenêtres enfants
this.OnLanguageChanged(sender, e);
}
}
Expand Down
Binary file modified GestionClient/GestionClient/bin/Debug/GestionClient.exe
Binary file not shown.
Binary file modified GestionClient/GestionClient/bin/Debug/GestionClient.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
Binary file not shown.
Binary file modified GestionClient/GestionClient/bin/Debug/data/gestionClient.mdb
Binary file not shown.
Binary file not shown.
Binary file modified GestionClient/GestionClient/obj/x86/Debug/GestionClient.exe
Binary file not shown.
Binary file modified GestionClient/GestionClient/obj/x86/Debug/GestionClient.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit b66ed5a

Please sign in to comment.