From 5950f7f5bfc8a89a207f2d45762a8a598dc9970f Mon Sep 17 00:00:00 2001 From: Evgenij Titarenko Date: Mon, 29 Jan 2024 21:02:33 +0300 Subject: [PATCH] Localization code + Russian localization --- locales/en.mo | Bin 0 -> 696 bytes locales/en.po | 36 ++++++++++++++++++++++++++++++++++++ locales/ru.mo | Bin 0 -> 858 bytes locales/ru.po | 37 +++++++++++++++++++++++++++++++++++++ locales/template.pot | 17 +++++++++++++++++ project.godot | 9 +++++++++ scenes/menu.tscn | 16 ++++++++++++++++ scripts/Menu.cs | 15 +++++++++++++++ scripts/WinScreen.cs | 4 +++- 9 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 locales/en.mo create mode 100644 locales/en.po create mode 100644 locales/ru.mo create mode 100644 locales/ru.po create mode 100644 locales/template.pot diff --git a/locales/en.mo b/locales/en.mo new file mode 100644 index 0000000000000000000000000000000000000000..6b296722847c7183e8b1734a689a1bf8ce686448 GIT binary patch literal 696 zcmd6k!D>@M6ozj#x|nXHh#-iZ>{{r=B&|?xxQkNL5=fiS+=|<2a*|w4X2Q&gcxk)t z6Zin`^c8#M3{yx?mgJf>__dGw=f(f}h|y z_zhly%2txRfWC(Qfxd-C|Nf)3KZ8cUherQBH2S|mVO>>aqfa&(cX_<|hHYIZy^FKU z6YrIen&=x=L-qS*b&_{?vywh7q$pfk}1=~%(<5IJ%>O8 zFF*9XhCsj)KlIxOkHZ(AHC`;qZeQMU52S{-rc__Lw((l=a z!r7Emzo#$xa}hiJ&In`FH9>UljSVv+&aWnRvNRLch@Jn_r^HsBch1`nfsI;Soj5FL zkx?#?C;Ua;V7$V-b5pI#v(RCrJKU;b;)2GhQLrQkB qYD3m+;kNN4+qG29sIk{lAM_bp_UnE7jz@*iLG7^CRLTGJ1b+dX@V7Dm literal 0 HcmV?d00001 diff --git a/locales/en.po b/locales/en.po new file mode 100644 index 0000000..c7e2ab2 --- /dev/null +++ b/locales/en.po @@ -0,0 +1,36 @@ +msgid "" +msgstr "" +"Project-Id-Version: \n" +"POT-Creation-Date: \n" +"PO-Revision-Date: \n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: en\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 3.4.2\n" + +msgid "Press Start or Enter" +msgstr "Press Start or Enter" + +msgid "by Tea Sanctuary, 2023" +msgstr "by Tea Sanctuary, 2023" + +msgid "CONGRATULATIONS!" +msgstr "CONGRATULATIONS!" + +msgid "" +"It took you\n" +"{0} attempts\n" +"and {1}\n" +"to finish the game." +msgstr "" +"It took you\n" +"{0} attempts\n" +"and {1}\n" +"to finish the game." + +msgid "Thank you for playing! :)" +msgstr "Thank you for playing! :)" diff --git a/locales/ru.mo b/locales/ru.mo new file mode 100644 index 0000000000000000000000000000000000000000..cb1f6751499f9d4580ccd44b6964c7e386309552 GIT binary patch literal 858 zcmZuvO-~b16de^^j4?6BXiSW`T}UK4wNq+B3IibsqzNAl6ywIlqkWXo_DwVMYHWZ6 zaKQpijFGtTd#5Xl2B|>cFWmV9{s9;M11*beDaW^S&)tmZEYKxoEV)NEX<4z7IKpl(+MM|NqgP{YIt>XA+aG_17rjl#T8u@224R;!4HtI7$=b{Vq` zDo8=oLKSsg_>CKsPNln{;@y`;ZRJYV9q9+Ir?O<`C#@;@(2YFnw$KuxF%f91;0qO0 zg!cS6qRMqqmKJ2I|M*$*>*jcFeE3MvPNvKu4+AP_G-}Y(@{zuY@m$qQ#d+ZeQadw+ z5v%8@F1l+@`qr>2dL_IfOFgr$HuIIbFDllE=U0O)saos?PIoU}8)ckp>Z+Y`9Gf~j zDLSSSj&0Kbr3mHl`@au$ubCdUo4|qRZ4VQU~H+i4GAh?UjO86xH z(NUTY!u4~Dta=tu89e@CE2+~Tj{a`-rD@EZty<2`O6v30lvNbjPm my$JjP+RbnUL0n9{&CS34@jgJe$=mT41(=2 && " +"n%10<=4 && (n%100<12 || n%100>14) ? 1 : 2);\n" +"X-Generator: Poedit 3.4.2\n" + +msgid "Press Start or Enter" +msgstr "Нажмите Start или Enter" + +msgid "by Tea Sanctuary, 2023" +msgstr "разработчик: Tea Sanctuary, 2023" + +msgid "CONGRATULATIONS!" +msgstr "ПОЗДРАВЛЯЕМ!" + +msgid "" +"It took you\n" +"{0} attempts\n" +"and {1}\n" +"to finish the game." +msgstr "" +"Вам потребовалось\n" +"{0} попыток\n" +"и {1}\n" +"чтобы пройти игру." + +msgid "Thank you for playing! :)" +msgstr "Спасибо за игру! :)" diff --git a/locales/template.pot b/locales/template.pot new file mode 100644 index 0000000..1208104 --- /dev/null +++ b/locales/template.pot @@ -0,0 +1,17 @@ +msgid "" +msgstr "" + +msgid "Press Start or Enter" +msgstr "" + +msgid "by Tea Sanctuary, 2023" +msgstr "" + +msgid "CONGRATULATIONS!" +msgstr "" + +msgid "It took you\n{0} attempts\nand {1}\nto finish the game." +msgstr "" + +msgid "Thank you for playing! :)" +msgstr "" \ No newline at end of file diff --git a/project.godot b/project.godot index 55f86cd..6a3b84c 100644 --- a/project.godot +++ b/project.godot @@ -71,6 +71,15 @@ ui_confirm={ , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":false,"script":null) ] } +ui_change_language={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":76,"key_label":0,"unicode":108,"echo":false,"script":null) +] +} + +[internationalization] + +locale/translations=PackedStringArray("res://locales/en.po", "res://locales/ru.po") [layer_names] diff --git a/scenes/menu.tscn b/scenes/menu.tscn index 298b9f5..523feac 100644 --- a/scenes/menu.tscn +++ b/scenes/menu.tscn @@ -281,6 +281,22 @@ text = "Press Start or Enter" horizontal_alignment = 1 vertical_alignment = 1 +[node name="Label2" type="Label" parent="CanvasLayer"] +anchors_preset = 12 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_top = -18.0 +offset_bottom = 8.00002 +grow_horizontal = 2 +grow_vertical = 0 +rotation = -0.001216 +auto_translate = false +theme = ExtResource("3_d3ur4") +text = "Press L to change language" +horizontal_alignment = 1 +vertical_alignment = 1 + [node name="Flash" type="TextureRect" parent="CanvasLayer"] clip_children = 2 material = SubResource("ShaderMaterial_eqq24") diff --git a/scripts/Menu.cs b/scripts/Menu.cs index ca2fb38..6b0a388 100644 --- a/scripts/Menu.cs +++ b/scripts/Menu.cs @@ -1,13 +1,21 @@ +using System.Collections.Generic; using Godot; +using Godot.Collections; public partial class Menu : Node2D { private Timer _timer; private AudioStreamPlayer2D _thunderclap; private AnimationPlayer _animationPlayer; + private Array _translations = new Array{"en", "ru"}; + private int _languagesCount; + private int _currentLanguage = 0; public override void _Ready() { + TranslationServer.SetLocale("en"); + _languagesCount = _translations.Count; + _timer = (Timer)FindChild("Timer"); _thunderclap = (AudioStreamPlayer2D)FindChild("Thunderclap"); _animationPlayer = (AnimationPlayer)FindChild("AnimationPlayer"); @@ -24,6 +32,13 @@ public partial class Menu : Node2D _thunderclap.Play(); _timer.Start(); } + else if (@event.IsActionPressed("ui_change_language")) + { + _currentLanguage++; + if (_currentLanguage >= _languagesCount) + _currentLanguage = 0; + TranslationServer.SetLocale(_translations[_currentLanguage]); + } } public void ChangeScene() diff --git a/scripts/WinScreen.cs b/scripts/WinScreen.cs index 76758c4..2e7723e 100644 --- a/scripts/WinScreen.cs +++ b/scripts/WinScreen.cs @@ -16,7 +16,9 @@ public partial class WinScreen : TextureRect Visible = true; TextLabel.Text = - $"It took you\n{Manager.GetAttempts()} attempts\nand {Manager.GetFormattedTimeElapsed()}\nto finish the game."; + string.Format(Tr("It took you\n{0} attempts\nand {1}\nto finish the game."), + Manager.GetAttempts(), + Manager.GetFormattedTimeElapsed()); } public override void _Input(InputEvent @event)