Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Docs/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -821,3 +821,17 @@ When enabled, the `RtlTextHandler` uses a smart token-based algorithm to:
- Logical Input: `قیمت 500 تومان`
- Rendered Output: `ناموت 500 تمیق`
*(The Persian words are reshaped and placed in correct RTL flow, while the English numbers remain LTR)*

### Generating TextMeshPro Fonts for Arabic/Persian

To display Arabic and Persian texts correctly in TextMeshPro, you need to generate a Font Asset that includes all the necessary characters (Base letters, Presentation Forms, and Diacritics).

We have provided a ready-to-use Unicode range file(s) at `Package/Assets`.

**How to generate the font:**

1. Open **Window > TextMeshPro > Font Asset Creator**.
2. Select your source TTF/OTF font (make sure it supports Arabic/Persian).
3. In the **Character Set** dropdown, choose **Custom Range**.
4. Open ranges file, copy its content, and paste it into the **Character Sequence (Hex)** box.
5. Generate the font atlas and save it.
1 change: 1 addition & 0 deletions Package/Assets/ArabicAll.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
060C,061B,061F,0621,0622,0623,0624,0625,0626,0627,0628,0629,062A,062B,062C,062D,062E,062F,0630,0631,0632,0633,0634,0635,0636,0637,0638,0639,063A,0640,0641,0642,0643,0644,0645,0646,0647,0648,0649,064A,067E,0686,0698,06A9,06AF,06CC,FB56,FB57,FB58,FB59,FB7A,FB7B,FB7C,FB7D,FB8A,FB8B,FB8C,FB8D,FB92,FB93,FB94,FB95,FB8E,FB8F,FB90,FB91,FBFC-FBFF,FE70-FEFF,064b-065f,0670,FC5E-FC63,0660-0669,06F0-06F9
1 change: 1 addition & 0 deletions Package/Assets/ArabicDigits.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0660-0669,06F0-06F9
1 change: 1 addition & 0 deletions Package/Assets/ArabicLetters.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
060C,061B,061F,0621,0622,0623,0624,0625,0626,0627,0628,0629,062A,062B,062C,062D,062E,062F,0630,0631,0632,0633,0634,0635,0636,0637,0638,0639,063A,0640,0641,0642,0643,0644,0645,0646,0647,0648,0649,064A,067E,0686,0698,06A9,06AF,06CC,FB56,FB57,FB58,FB59,FB7A,FB7B,FB7C,FB7D,FB8A,FB8B,FB8C,FB8D,FB92,FB93,FB94,FB95,FB8E,FB8F,FB90,FB91,FBFC-FBFF,FE70-FEFF
1 change: 1 addition & 0 deletions Package/Assets/ArabicTashkil.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
064b-065f,0670,FC5E-FC63
1 change: 1 addition & 0 deletions Package/Assets/HebrewLetters.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0591-05C7,05D0-05EA,05EF-05F4
6 changes: 6 additions & 0 deletions Package/Core/LocalizationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,15 @@ public static void Initialize()
#endif
}

#if UNITY_EDITOR
string targetLanguage = !string.IsNullOrEmpty(_currentLanguageCode) && _availableLanguages.Contains(_currentLanguageCode)
? _currentLanguageCode
: (!Application.isPlaying && _availableLanguages.Contains(DefaultLanguage) ? DefaultLanguage : DetectSystemLanguage());
#else
string targetLanguage = !string.IsNullOrEmpty(_currentLanguageCode) && _availableLanguages.Contains(_currentLanguageCode)
? _currentLanguageCode
: DetectSystemLanguage();
#endif

SetLanguage(targetLanguage, useFallback: false);

Expand Down
33 changes: 30 additions & 3 deletions Package/Editor/Tabs/KeysTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public sealed class KeysTab : LocalizationEditorTabBase
private string _newKey = "";
private string _newValue = "";
private bool _pendingDelete;
private bool _isTranslating;
private float _keysListViewportHeight;

private static Texture2D _transparentTexture;
Expand Down Expand Up @@ -478,8 +479,10 @@ private void DrawKeyActionButtons()
if (GUILayout.Button("Rename", GUILayout.Width(65)))
RenameKey();

if (GUILayout.Button("Translate", GUILayout.Width(65)))
_ = _translationService.TranslateAndFill(Data.SelectedKey);
EditorGUI.BeginDisabledGroup(_isTranslating);
if (GUILayout.Button(_isTranslating ? "Translating..." : "Translate", GUILayout.Width(85)))
ExecuteTranslation();
EditorGUI.EndDisabledGroup();

if (GUILayout.Button("Copy", GUILayout.Width(55)))
ShowCopyKeyMenu();
Expand Down Expand Up @@ -546,6 +549,30 @@ private void ShowJsonOptionsMenu()
menu.ShowAsContext();
}

private async void ExecuteTranslation()
{
if (_isTranslating || string.IsNullOrEmpty(Data.SelectedKey)) return;

_isTranslating = true;
Editor.Repaint();

try
{
await _translationService.TranslateAndFill(Data.SelectedKey);
Editor.ShowNotification(new GUIContent("Translation completed successfully!"));
}
catch (Exception ex)
{
Debug.LogError($"Translation failed: {ex.Message}");
Editor.ShowNotification(new GUIContent("Translation failed!"));
}
finally
{
_isTranslating = false;
Editor.Repaint();
}
}

private void AddKey(bool isArray)
{
string cleanKey = _newKey?.Trim();
Expand Down Expand Up @@ -707,7 +734,7 @@ public override bool HandleKeyboardInput(Event evt)
case KeyCode.T:
if (ctrlPressed)
{
_ = _translationService.TranslateAndFill(Data.SelectedKey);
ExecuteTranslation();
evt.Use();
return true;
}
Expand Down