Skip to content

Commit

Permalink
Localisation WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mlavik1 committed Mar 23, 2024
1 parent 25772d9 commit 1f0858e
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
81 changes: 81 additions & 0 deletions Assets/Localisation/LocalisationManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using UnityEngine;

namespace UnityVolumeRendering
{
public class LocalisationManager
{
private enum Locale
{
English,
Chinese
}

private struct LocalisationEntry
{
public string english;
public string chineseSimplified;
}

private static Locale currentLocale = Locale.English;

private static Dictionary<string, LocalisationEntry> translations = new Dictionary<string, LocalisationEntry>()
{
{"MenuBar:VolumeRendering", new LocalisationEntry {
english= "Volume Rendering",
chineseSimplified= "体绘制"
}},
{"MenuBar:LoadDataset", new LocalisationEntry {
english= "Load dataset",
chineseSimplified= "导入数据集"
}},
{"MenuBar:LoadDICOM", new LocalisationEntry {
english= "Load DICOM",
chineseSimplified= "导入DICOM数据"
}},
{"MenuBar:LoadRaw", new LocalisationEntry {
english= "Load raw dataset",
chineseSimplified= "导入RAW数据"
}},
{"MenuBar:LoadNRRD", new LocalisationEntry {
english= "Load NRRD dataset",
chineseSimplified= "导入NRRD数据"
}},
{"MenuBar:LoadNIFTI", new LocalisationEntry {
english= "Load NIFTI dataset",
chineseSimplified= "导入NIFTI数据"
}},
{"MenuBar:LoadPARCHG", new LocalisationEntry {
english= "Load PARCHG dataset",
chineseSimplified= "导入PARCHG数据"
}},
{"MenuBar:LoadNIFTI", new LocalisationEntry {
english= "Load image sequence dataset",
chineseSimplified= "导入图像序列格式"
}}
};

static LocalisationManager()
{
currentLocale = Locale.English;
#if UNITY_EDITOR
if (UnityEditor.EditorPrefs.GetString("Editor.kEditorLocale") == "ChineseSimplified")
currentLocale = Locale.Chinese;
#endif
if (!Application.isEditor && Application.systemLanguage.ToString() == "ChineseSimplified")
currentLocale = Locale.Chinese;
}

public static string GetString(string id)
{
if (!translations.ContainsKey(id))
{
Debug.LogWarning("Localisation key not found: " + id);
return "";
}
LocalisationEntry translation = translations[id];
return currentLocale == Locale.Chinese ? translation.chineseSimplified : translation.english;
}
}
}
11 changes: 11 additions & 0 deletions Assets/Localisation/LocalisationManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1f0858e

Please sign in to comment.