1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using System.Collections.Generic;
- using System.IO;
- using System.Text.Json;
- namespace AILicenseGenerator.Helper
- {
- public class TranslateHelper
- {
- private static Dictionary<string, string> _dict = new Dictionary<string, string>();
- public static void Init(Dictionary<string, string> dict)
- {
- _dict = dict;
- }
- public static void Init(string path)
- {
- try
- {
- if (File.Exists(path))
- {
- var content = File.ReadAllText(path);
- _dict = JsonSerializer.Deserialize<Dictionary<string, string>>(content, new JsonSerializerOptions
- {
- AllowTrailingCommas = true
- });
- }
- }
- catch
- {
- }
- }
- public static string Translate(string text)
- {
- if (string.IsNullOrEmpty(text))
- {
- return null;
- }
- if (_dict.ContainsKey(text))
- {
- return _dict[text];
- }
- else
- {
- return text;
- }
- }
- }
- }
|