Skip to content

Instantly share code, notes, and snippets.

@s2kw
Created October 31, 2024 15:45
Show Gist options
  • Save s2kw/2e8240cfecc5fec1585c54a17916a7ea to your computer and use it in GitHub Desktop.
Save s2kw/2e8240cfecc5fec1585c54a17916a7ea to your computer and use it in GitHub Desktop.
アラビア語対応をしていたら 0 がゼロじゃない文字になっていたので困ったがClaudeは一発で答えてくれた。
public static class ArabicTextFormatter
{
private static readonly CultureInfo arabicCulture = new CultureInfo("ar-SA");
public static string FormatArabicText(string format, object value)
{
try
{
// 1. まず数値を変換
string numStr;
if (value is float f)
{
numStr = f.ToString(arabicCulture);
}
else if (value is int i)
{
numStr = i.ToString(arabicCulture);
}
else
{
numStr = value.ToString();
}
// 2. プレースホルダーを置換
// 異なるプレースホルダーのパターンに対応
string result = format
.Replace("{0}", numStr)
.Replace("٠", numStr) // アラビア数字の0
.Replace("(0)", numStr);
return result;
}
catch (Exception ex)
{
Debug.LogError($"Error formatting Arabic text: {format} with value: {value}\nError: {ex.Message}");
return format;
}
}
}
// 使用例
public class ItemExplainManager
{
public string GetFormattedExplanation(ItemExplainData data)
{
var translated = CM_LanguageChanger.GetText(data.explainText_Key);
Debug.Log($"Original text: {data.explainText_Key} -> {translated}");
// ArabicTextFormatterを使用
var formattedText = ArabicTextFormatter.FormatArabicText(translated, data.value);
Debug.Log($"Formatted text: {formattedText}");
return formattedText;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment