Skip to content

Commit

Permalink
Merge pull request #80 from ligen131/feat-20240917-init-i18n
Browse files Browse the repository at this point in the history
feat(i18n): 新增本地化
  • Loading branch information
cutekibry authored Sep 17, 2024
2 parents de14a70 + 0456f25 commit 889a666
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 59 deletions.
42 changes: 42 additions & 0 deletions lang/translations.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
keys,en,zh,ja
CHAPTER_PATTERN,"Ch. %d %s","第 %d 章 %s",""
CHAPTER_NAME_0,"=P","=P","=P"
CHAPTER_NAME_1,"Add and Multiply","加法和乘法",""
CHAPTER_NAME_2,"()","()",""
CHAPTER_NAME_3,"Equal?","相等?",""
CHAPTER_NAME_4,"<>","<>",""
CHAPTER_NAME_5,"Extra Challenges","额外挑战",""

LEVEL_NAME_0_0,"P=P","P=P","P=P"
LEVEL_NAME_0_1,"=P","=P","=P"
LEVEL_NAME_0_2,"Another Smile","Another Smile","Another Smile"
LEVEL_NAME_0_3,"Reverse","Reverse","Reverse"
LEVEL_NAME_0_4,"Reverse Again","Reverse Again","Reverse Again"
LEVEL_NAME_0_5,"Snake","Snake","Snake"

LEVEL_NAME_1_0,"0+0=0, 0+1=1","0+0=0, 0+1=1","0+0=0, 0+1=1"
LEVEL_NAME_1_1,"1+1=1","1+1=1","1+1=1"
LEVEL_NAME_1_2,"Swap","交换","Swap"
LEVEL_NAME_1_3,"Always True","Always True","Always True"
LEVEL_NAME_1_4,"Paper Tiger","纸老虎","Paper Tiger"
LEVEL_NAME_1_5,"Make Me Laugh","Make Me Laugh","Make Me Laugh"
LEVEL_NAME_1_6,"Reset","重置","Reset"
LEVEL_NAME_1_7,"Not Necessary","并非必要","Not Necessary"
LEVEL_NAME_1_8,"True Reset","真正的重置","True Reset"
LEVEL_NAME_1_9,"Gold Experience","黄金体验","Gold Experience"

LEVEL_NAME_2_0,"He Goes First","He Goes First","He Goes First"
LEVEL_NAME_2_1,"Still, He Goes First","Still, He Goes First","Still, He Goes First"
LEVEL_NAME_2_2,"It's My Turn","It's My Turn","It's My Turn"

LEVEL_NAME_3_0,"Missing Equation","缺失的等式","Missing Equation"
LEVEL_NAME_3_1,"Why?","Why?","Why?"
LEVEL_NAME_3_2,"Where is the Equation?","Where is the Equation?","Where is the Equation?"
LEVEL_NAME_3_3,"Untitled","Untitled","Untitled"

LEVEL_NAME_4_0,"<","<","<"
LEVEL_NAME_4_1,"<=","<=","<="
LEVEL_NAME_4_2,"<>","<>","<>"

LEVEL_NAME_5_0,"[EX] Erase Which?","[EX] Erase Which?","[EX]Erase Which?"
LEVEL_NAME_5_1,"[EX] Really Challenging","[EX] Really Challenging","[EX] Really Challenging"
17 changes: 17 additions & 0 deletions lang/translations.csv.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[remap]

importer="csv_translation"
type="Translation"
uid="uid://g1rl4ude18st"

[deps]

files=["res://lang/translations.en.translation", "res://lang/translations.zh.translation", "res://lang/translations.ja.translation"]

source_file="res://lang/translations.csv"
dest_files=["res://lang/translations.en.translation", "res://lang/translations.zh.translation", "res://lang/translations.ja.translation"]

[params]

compress=true
delimiter=0
Binary file added lang/translations.en.translation
Binary file not shown.
Binary file added lang/translations.ja.translation
Binary file not shown.
Binary file added lang/translations.zh.translation
Binary file not shown.
4 changes: 2 additions & 2 deletions levels/base_level/base_level.gd
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ func init(_chap_id: int, _lvl_id: int) -> void:
chap_id = _chap_id
lvl_id = _lvl_id

var lvl_name = LevelData.LEVEL_DATA[chap_id][lvl_id]["name-en"]
var lvl_name = "LEVEL_NAME_%d_%d" % [chap_id, lvl_id]
var question = LevelData.LEVEL_DATA[chap_id][lvl_id]["question"].replace(" ", "").replace("X", "*")
var choices = count(LevelData.LEVEL_DATA[chap_id][lvl_id]["choices"].replace(" ", "").replace("X", "*"))


$HUDs/Title.set_text("%d-%d %s" % [chap_id + 1, lvl_id + 1, lvl_name])
$HUDs/Title.set_text("%d-%d %s" % [chap_id + 1, lvl_id + 1, tr(lvl_name)])


question = question.replace("[]", ".")
Expand Down
6 changes: 3 additions & 3 deletions levels/chapter_menu/level_menu/level_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const button_heigth : int = 50

func init(chap_id: int) -> void:
self.chapter_id = chap_id
$UI/Title.text = LevelData.CHAP_NAMES[chapter_id]["name-en"]
$UI/Title.text = tr("CHAPTER_PATTERN") % [chap_id + 1, tr("CHAPTER_NAME_%d" % chap_id)]
$LevelMenuCamera.init_position(Vector2(WIDTH * chap_id, 0))

$UI/PreviousChapterButton.set_disabled(chapter_id == 0)
Expand All @@ -42,7 +42,7 @@ func _on_button_enter_level(chap_id: int, lvl_id: int) -> void:

func _on_previous_chapter_button_pressed():
self.chapter_id -= 1
$UI/Title.text = LevelData.CHAP_NAMES[chapter_id]["name-en"]
$UI/Title.text = tr("CHAPTER_PATTERN") % [self.chapter_id + 1, tr("CHAPTER_NAME_%d" % self.chapter_id)]
ImageLib.change_theme(ImageLib.COLOR_THEMES[ImageLib.COLOR_THEMES.find(ImageLib.theme_to) - 1], LevelMenuCamera.MOVE_TIME)
$UI/PreviousChapterButton.set_disabled(true)
$UI/NextChapterButton.set_disabled(true)
Expand All @@ -51,7 +51,7 @@ func _on_previous_chapter_button_pressed():
func _on_next_chapter_button_pressed():
self.chapter_id += 1
ImageLib.change_theme(ImageLib.COLOR_THEMES[ImageLib.COLOR_THEMES.find(ImageLib.theme_to) + 1], LevelMenuCamera.MOVE_TIME)
$UI/Title.text = LevelData.CHAP_NAMES[chapter_id]["name-en"]
$UI/Title.text = tr("CHAPTER_PATTERN") % [self.chapter_id + 1, tr("CHAPTER_NAME_%d" % self.chapter_id)]
$UI/PreviousChapterButton.set_disabled(true)
$UI/NextChapterButton.set_disabled(true)

Expand Down
4 changes: 4 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ enabled=PackedStringArray("res://addons/AsepriteWizard/plugin.cfg")
theme/custom="res://themes/default_theme.tres"
theme/custom_font="res://fonts/Silver.ttf"

[internationalization]

locale/translations=PackedStringArray("res://lang/translations.en.translation", "res://lang/translations.ja.translation", "res://lang/translations.zh.translation")

[rendering]

textures/canvas_textures/default_texture_filter=0
Expand Down
54 changes: 0 additions & 54 deletions scripts/level_data.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,6 @@
class_name LevelData



## 各章节的名称。
## [br][br]
## [code]CHAP_NAMES[chapter_id]["name-en"][/code] 返回第 [param chapter_id] 章节的英文名称(包含 [code]Ch.[/code] 前缀)。
const CHAP_NAMES := [
{
"name-en": "Ch. 1 =P",
},
{
"name-en": "Ch. 2 Add and Multiply",
},
{
"name-en": "Ch. 3 ()",
},
{
"name-en": "Ch. 4 Equal?",
},
{
"name-en": "Ch. 5 <>",
},
{
"name-en": "Ch. EX Challenge Levels",
}
]


## 各关卡的关卡数据。
## [br][br]
## [code]LEVEL_DATA[chapter_id][level_id] : Dictionary[/code] 返回第 [param chapter_id] 章节的第 [param level_id] 关卡的关卡数据,以下记为 [code]data[/code]。其中:
Expand All @@ -40,157 +14,129 @@ const CHAP_NAMES := [
const LEVEL_DATA := [
[
{
"name-en": "=P",
"question": "P [] []",
"choices": "= P"
},
{
"name-en": "Smile",
"question": "P {} {}",
"choices": "= P P"
},
{
"name-en": "Another Smile",
"question": "[] = {}",
"choices": "R R P D D"
},
{
"name-en": "Reverse",
"question": "{} [] []",
"choices": "D D = d d"
},
{
"name-en": "Reverse Again",
"question": "[] {} {}",
"choices": "d d = R R b b"
},
{
"name-en": "Snake",
"question": "[] = {} = {} = [] = {} = {}",
"choices": "dddddd QQQQQQ RRRRRR DDDDDD PPPPPP qqqqqq"
}
],

[
{
"name-en": "0+0=0, 0+1=1",
"question": "[] [] {} {} d",
"choices": "= + 0 d"
},
{
"name-en": "1+1=1",
"question": "[] [] {} {} 1",
"choices": "= + 1 d"
},
{
"name-en": "Swap",
"question": "Q + [] = {} + []",
"choices": "P P P P Q Q Q Q"
},
{
"name-en": "Always True",
"question": "1 [] {} = {} [] []",
"choices": "1++PPdd"
},
{
"name-en": "Paper Tiger",
"question": "1 [] [] [] {} [] [] [] {} [] {} [] []",
"choices": "== ++++++ 11 P q b R"
},
{
"name-en": "Make Me Laugh",
"question": "1 {} {} = []",
"choices": "XDD"
},
{
"name-en": "Reset",
"question": "0 [] [] {} []",
"choices": "XP=0"
},
{
"name-en": "Not Necessary",
"question": "[] {} {} {} {} []",
"choices": "QQQQQQ DDXX="
},
{
"name-en": "True Reset",
"question": "[] + [] [] [] [] {} = {} [] [] [] [] [] []",
"choices": "0 0 1 d d q P P b R R Q +"
},
{
"name-en": "Gold Experience",
"question": "{} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}",
"choices": "PP DD bb qq dd XXXXX ="
},
],

[
{
"name-en": "He Goes First",
"question": "[] [] + [] = ( [] {} {} ) [] []",
"choices": "PP QQ RR X +"
},
{
"name-en": "Still, He Goes First",
"question": "[] + [] [] = [] [] ( [] {} {} )",
"choices": "PP QQ RR X +"
},
{
"name-en": "It's My Turn",
"question": "P ([] [] []) = {} [] [] [] []",
"choices": "PP QQ RR ++"
},
],

[
{
"name-en": "Missing Equation",
"question": "[] + [] {} {}",
"choices": "P P P 1 X",
},
{
"name-en": "Why?",
"question": "[] [] {} = {} [] {} = []",
"choices": "PP qq ++ 1"
},
{
"name-en": "Where is the Equation?",
"question": "[] [] {} {} [] + [] [] {} {} []",
"choices": "(())==01PP"
},

{
"name-en": "Untitled",
"question": "[] [] {} {} [] [] [] []",
"choices": "=PPQQ+()"
}
],

[
{
"name-en": "<",
"question": "0 {} {} [] 1",
"choices": "XD<"
},
{
"name-en": "<=",
"question": "[] X [] {} {} [] + []",
"choices": "QQPP<="
},
{
"name-en": "<>",
"question": "0 {} P [] [] []",
"choices": "<>=P"
}
],
[
{
"name-en": "[EX]Erase Which?",
"question": "[] {} {} [] [] [] [] {} {} {} {} {} [] [] [] [] [] []",
"choices": "0 X D + P + P d = P X P + 0 d + P d",
},
{
"name-en": "[EX] Really Challenging",
"question": "[] [] [] [] [] {} {} [] [] [] [] {} {} + [] []",
"choices": "PPP QQ DD (()) ++ = X"
},
Expand Down

0 comments on commit 889a666

Please sign in to comment.