-
-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple languages & Language adaptation #224
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
using CitizenFX.Core; | ||
using static CitizenFX.Core.Native.API; | ||
using Newtonsoft.Json; | ||
using System.Collections; | ||
|
||
namespace vMenuShared | ||
{ | ||
|
@@ -93,12 +94,50 @@ public static bool IsClientDebugModeEnabled() | |
return GetResourceMetadata("vMenu", "client_debug_mode", 0).ToLower() == "true"; | ||
} | ||
|
||
#region Get saved locations from the locations.json | ||
#region Get localization from the languages.json | ||
/// <summary> | ||
/// Gets the locations.json data. | ||
/// Gets the languages.json data. | ||
/// </summary> | ||
/// <returns></returns> | ||
public static Locations GetLocations() | ||
public static Dictionary<string, Hashtable> GetLanguages() | ||
{ | ||
Dictionary<string, Hashtable> data = new Dictionary<string, Hashtable>(); | ||
|
||
string jsonFile = LoadResourceFile(GetCurrentResourceName(), "config/languages.json"); | ||
try | ||
{ | ||
if (string.IsNullOrEmpty(jsonFile)) | ||
{ | ||
#if CLIENT | ||
vMenuClient.Notify.Error("The languages.json file is empty or does not exist, please tell the server owner to fix this."); | ||
#endif | ||
#if SERVER | ||
vMenuServer.DebugLog.Log("The languages.json file is empty or does not exist, please fix this.", vMenuServer.DebugLog.LogLevel.error); | ||
#endif | ||
} | ||
else | ||
{ | ||
data = JsonConvert.DeserializeObject<Dictionary<string, Hashtable>>(jsonFile); | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
#if CLIENT | ||
vMenuClient.Notify.Error("An error occurred while processing the languages.json file. Language will set to English. Please correct any errors in the languages.json file."); | ||
#endif | ||
Debug.WriteLine($"[vMenu] json exception details: {e.Message}\nStackTrace:\n{e.StackTrace}"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
return data; | ||
} | ||
#endregion | ||
|
||
#region Get saved locations from the locations.json | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is there an additional indentation level here? |
||
/// <summary> | ||
/// Gets the locations.json data. | ||
/// </summary> | ||
/// <returns></returns> | ||
public static Locations GetLocations() | ||
{ | ||
Locations data = new Locations(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using MenuAPI; | ||
using Newtonsoft.Json; | ||
using CitizenFX.Core; | ||
using static CitizenFX.Core.UI.Screen; | ||
using static CitizenFX.Core.Native.API; | ||
using static vMenuClient.CommonFunctions; | ||
using static vMenuShared.ConfigManager; | ||
using static vMenuShared.PermissionsManager; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is all this really necessary? |
||
|
||
namespace vMenuClient | ||
{ | ||
public class LanguageManager : BaseScript | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this use BaseScript? |
||
{ | ||
public string Get (string originalText) { | ||
|
||
string transText = originalText; | ||
|
||
if (!MainMenu.DumpedData.ContainsKey(originalText)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the "DumpedData" in MainMenu? |
||
{ | ||
MainMenu.DumpedData.Add(originalText, ""); | ||
} | ||
|
||
if (MainMenu.CurrentLanguage.ContainsKey(originalText)) { | ||
try { | ||
transText = (string)MainMenu.CurrentLanguage[originalText]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This try / catch is not needed, you've already checked if the text is in there so nothing should raise an exception here. |
||
if (transText == "") | ||
{ | ||
transText = originalText; | ||
} | ||
} catch (Exception ex) | ||
{ | ||
// Not need this because it will generate lot of logs and fill your disk xD | ||
// Debug.WriteLine($"Cannot found translate: {originalText}"); | ||
} | ||
} | ||
|
||
return transText; | ||
} | ||
} | ||
} |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ public class NoClip : BaseScript | |
private static int Scale { get; set; } = -1; | ||
private static bool FollowCamMode { get; set; } = false; | ||
|
||
private static LanguageManager LM = new LanguageManager(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems a bit useless? 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to add a translation for the NoClip button, but it crashed, seemingly because it was loaded earlier than the main menu. |
||
|
||
private List<string> speeds = new List<string>() | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,22 +18,23 @@ public class About | |
// Variables | ||
private Menu menu; | ||
|
||
private static LanguageManager LM = new LanguageManager(); | ||
private void CreateMenu() | ||
{ | ||
// Create the menu. | ||
menu = new Menu("vMenu", "About vMenu"); | ||
menu = new Menu(LM.Get("vMenu"), LM.Get("About vMenu")); | ||
|
||
// Create menu items. | ||
MenuItem version = new MenuItem("vMenu Version", $"This server is using vMenu ~b~~h~{MainMenu.Version}~h~~s~.") | ||
MenuItem version = new MenuItem(LM.Get("vMenu Version"), $"This server is using vMenu ~b~~h~{MainMenu.Version}~h~~s~.") | ||
{ | ||
Label = $"~h~{MainMenu.Version}~h~" | ||
}; | ||
MenuItem credits = new MenuItem("About vMenu / Credits", "vMenu is made by ~b~Vespura~s~. For more info, checkout ~b~www.vespura.com/vmenu~s~. Thank you to: Deltanic, Brigliar, IllusiveTea, Shayan Doust and zr0iq for your contributions."); | ||
MenuItem credits = new MenuItem(LM.Get("About vMenu / Credits"), LM.Get("vMenu is made by ~b~Vespura~s~. For more info, checkout ~b~www.vespura.com/vmenu~s~. Thank you to: Deltanic, Brigliar, IllusiveTea, Shayan Doust and zr0iq for your contributions.")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Credits shouldn't need to be translated or possibly removed. |
||
|
||
string serverInfoMessage = vMenuShared.ConfigManager.GetSettingsString(vMenuShared.ConfigManager.Setting.vmenu_server_info_message); | ||
if (!string.IsNullOrEmpty(serverInfoMessage)) | ||
{ | ||
MenuItem serverInfo = new MenuItem("Server Info", serverInfoMessage); | ||
MenuItem serverInfo = new MenuItem(LM.Get("Server Info"), serverInfoMessage); | ||
string siteUrl = vMenuShared.ConfigManager.GetSettingsString(vMenuShared.ConfigManager.Setting.vmenu_server_info_website_url); | ||
if (!string.IsNullOrEmpty(siteUrl)) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please only try/catch the necessary code. Only the JSON conversion could crash here, so that's what needs to be caught.