feat(localization): add localization for scripted texts

This commit is contained in:
Fangh 2024-02-27 23:46:29 +01:00
parent ad12dd2cdf
commit 350109262d
4 changed files with 2861 additions and 120 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,10 @@
using Newtonsoft.Json;
using TMPro;
using Unity.VisualScripting;
using UnityEditor.Localization;
using UnityEngine;
using UnityEngine.Localization.Settings;
using UnityEngine.Localization.Tables;
using UnityEngine.UI;
/// <summary>
@ -20,6 +23,7 @@ public class GameManager : MonoBehaviour
[Header("Other component")]
public float explanationTime = 4f;
public StringTableCollection stringTableCollection;
[Header("Home Connection Component")]
public TMP_InputField roomCodeField;
@ -54,11 +58,17 @@ public class GameManager : MonoBehaviour
public GameObject WaitingOtherPlayers;
public GameObject EndGame;
internal Room myRoom;
private DatabaseReference realtimeDB;
public Room myRoom;
private DatabaseReference myOnlineRoom;
private DateTime endOfViewDate = DateTime.MinValue;
/// <summary>
/// Contains all the translated string for the UI
/// </summary>
private StringTable stringTable;
private void Awake()
{
submitNewPlayer.interactable = false;
@ -68,6 +78,7 @@ private void Awake()
private void Start()
{
InitializeHomePage();
stringTable = stringTableCollection.GetTable(LocalizationSettings.SelectedLocale.Identifier) as StringTable;
}
private void InitializeHomePage()
@ -162,7 +173,8 @@ public void PlayerValidateNameAndServerRoom(string _name, string _code)
{
Debug.LogError("Player name is empty", this);
nameError.text = "You have to put a valid name";
string errorText = stringTable.GetEntry("PhoneView/Canvas/Background/HomeState/NameField/ErrorNameLabel").LocalizedValue;
nameError.text = errorText;
nameError.gameObject.SetActive(true);
submitNewPlayer.interactable = true;
@ -172,7 +184,9 @@ public void PlayerValidateNameAndServerRoom(string _name, string _code)
if (string.IsNullOrEmpty(_code))
{
Debug.LogError("Room code is empty", this);
roomError.text = "You have to put a room code";
string errorText = stringTable.GetEntry("PhoneView/Canvas/Background/HomeState/NameField/EmptyRoom").LocalizedValue;
roomError.text = errorText;
roomError.gameObject.SetActive(true);
submitNewPlayer.interactable = true;
@ -189,7 +203,8 @@ public void PlayerValidateNameAndServerRoom(string _name, string _code)
if (room == null)
{
Debug.LogError("The room doesn't exists");
roomError.text = "Error: the room doesn't exists";
string errorText = stringTable.GetEntry("PhoneView/Canvas/Background/HomeState/NameField/ErrorRoom").LocalizedValue;
roomError.text = errorText;
roomError.gameObject.SetActive(true);
submitNewPlayer.interactable = true;
}

View File

@ -6,9 +6,11 @@
using UnityEngine;
using Newtonsoft.Json;
using System.Linq;
using Firebase.Storage;
using System.Threading.Tasks;
using System.Collections;
using UnityEditor.Localization;
using UnityEngine.Localization.Settings;
using UnityEngine.Localization;
using UnityEngine.Localization.Tables;
public class RoomManager : MonoBehaviour
{
@ -41,6 +43,12 @@ public class RoomManager : MonoBehaviour
[Header("Other")]
public PromptList promptList;
public StringTableCollection stringTableCollection;
/// <summary>
/// Contains all the translated string for the UI
/// </summary>
private StringTable stringTable;
public Room myRoom { get; private set; } = null;
@ -50,6 +58,7 @@ private void Awake()
{
Instance = this;
FirebaseInitializer.Instance.onFirebaseReady += Initialize;
stringTable = stringTableCollection.GetTable(LocalizationSettings.SelectedLocale.Identifier) as StringTable;
}
private void Start()
@ -96,9 +105,10 @@ private void SendRoomState(GameState _newState)
private void ResetAllPlayerLabels()
{
string label = stringTable.GetEntry("ComputerView/Canvas/WaitingForPlayersPage/WaitingForP").LocalizedValue;
for (int i = 0; i < playerStickers.Count; i++)
{
playerStickers[i].Initialize($"Waiting for P{i + 1}", i);
playerStickers[i].Initialize($"{label}{i + 1}", i);
}
}