多语言逻辑

This commit is contained in:
bob
2025-06-13 17:35:29 +08:00
parent f862c7514c
commit e060f9eb02
18 changed files with 561 additions and 221 deletions

View File

@@ -1,6 +1,9 @@
namespace NBC
using System.Collections.Generic;
using FairyGUI;
namespace NBC
{
public class Lan
public static class Lan
{
private static LanguageManager _inst;
@@ -19,18 +22,59 @@
public static ILanguage Text => Inst.GetLanguageModule((int)LanguageModuleType.Text);
public static string Get(string key)
public static void SetLanguage(this GObject child, string key, params object[] args)
{
if(Text == null) return key;
return Text.Get(key);
if (Text == null) return;
child.lang = key;
var value = Text.Get(key);
if (args != null && args.Length > 0)
{
value = string.Format(value, args);
child.langArgs = args;
}
else
{
child.langArgs = null;
}
if (child is GRichTextField richTextField)
{
richTextField.text = value;
}
else if (child is GButton button)
{
button.title = value;
}
else if (child is GLabel label)
{
label.title = value;
}
else if (child is GTextField gtextField)
{
gtextField.text = value;
}
}
public static string Get(string key, params object[] args)
public static void SetLanguageImage(this GObject obj, string key)
{
var format = string.Format(Text.Get(key), args);
return format;
}
// public static string Get(string key)
// {
// if(Text == null) return key;
// return Text.Get(key);
// }
//
// public static string Get(string key, params object[] args)
// {
// var format = string.Format(Text.Get(key), args);
// return format;
// }
public static string GetLanImagePath(string key)
{
return Inst.GetLanguageModule((int)LanguageModuleType.Image).Get(key);