Skip to content

Commit 5bda007

Browse files
CalinouSkyLucilfer
andauthored
Update GUI Translation demo for 4.0 (#930)
- Add PO support in addition to CSV. Co-authored-by: SkyJJ <[email protected]>
1 parent f70868c commit 5bda007

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+812
-323
lines changed

gui/translation/README.md

+27-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
11
# GUI Translation Demo
22

3-
A demo showing how Godot seamlessly enables
4-
the use of localized resources and texts.
3+
This is a demo of how a project can be internationalized. Translations are
4+
created in a CSV file and then imported into Godot.
5+
6+
For correct display, the font used must contain the glyphs required by the
7+
target language. See the `fonts` folder for some fonts that you can use in your
8+
project. Godot can load system fonts as a fallback, but this is not supported on
9+
all platforms and the different visual design of system fonts can create
10+
inconsistencies.
11+
12+
Godot allows internationalized text to change automatically when the locale is
13+
modified. Resources can also be set to internationalized alternatives and replaced
14+
automatically on locale change. This process is known as *remapping*.
15+
16+
Both CSV and gettext (PO/POT) approaches are showcased. Use the button in the
17+
bottom-right corner to switch between the two approaches.
18+
19+
The resouce remapping process with PO is the same with CSV. The in-game text translation
20+
process is also the same – use keys to fetch the appropriate translation.
21+
22+
The main difference between PO files and CSV files is the way both of them store
23+
the translated data in their files. Have a look at the `translations/po`
24+
and `translations/csv` folders to see the files involved.
25+
26+
See [Internationalizing games](https://docs.godotengine.org/en/latest/tutorials/i18n/internationalizing_games.html)
27+
and [Localization using gettext](https://docs.godotengine.org/en/latest/tutorials/i18n/localization_using_gettext.html)
28+
for more information.
529

630
Language: GDScript
731

832
Renderer: Compatibility
933

10-
Check out this demo on the asset library: https://godotengine.org/asset-library/asset/134
11-
1234
## Screenshots
1335

14-
![Screenshot](screenshots/translation.png)
36+
![Screenshot](screenshots/translation.webp)
File renamed without changes.
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[remap]
2+
3+
importer="wav"
4+
type="AudioStreamWAV"
5+
uid="uid://ciept8j0x21to"
6+
path="res://.godot/imported/hello_en.wav-2eea592f221b07e3c37c5477c1da8173.sample"
7+
8+
[deps]
9+
10+
source_file="res://audio/hello_en.wav"
11+
dest_files=["res://.godot/imported/hello_en.wav-2eea592f221b07e3c37c5477c1da8173.sample"]
12+
13+
[params]
14+
15+
force/8_bit=false
16+
force/mono=false
17+
force/max_rate=false
18+
force/max_rate_hz=44100
19+
edit/trim=false
20+
edit/normalize=false
21+
edit/loop_mode=0
22+
edit/loop_begin=0
23+
edit/loop_end=-1
24+
compress/mode=0
File renamed without changes.
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[remap]
2+
3+
importer="wav"
4+
type="AudioStreamWAV"
5+
uid="uid://dd4xk00uh27hj"
6+
path="res://.godot/imported/hello_es.wav-0b3ee7fc19ef7ac4822f3f3dc177c570.sample"
7+
8+
[deps]
9+
10+
source_file="res://audio/hello_es.wav"
11+
dest_files=["res://.godot/imported/hello_es.wav-0b3ee7fc19ef7ac4822f3f3dc177c570.sample"]
12+
13+
[params]
14+
15+
force/8_bit=false
16+
force/mono=false
17+
force/max_rate=false
18+
force/max_rate_hz=44100
19+
edit/trim=false
20+
edit/normalize=false
21+
edit/loop_mode=0
22+
edit/loop_begin=0
23+
edit/loop_end=-1
24+
compress/mode=0
File renamed without changes.
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[remap]
2+
3+
importer="wav"
4+
type="AudioStreamWAV"
5+
uid="uid://3tnymbrsqo0w"
6+
path="res://.godot/imported/hello_jp.wav-c7c916ef924fa85620d3858f227d094f.sample"
7+
8+
[deps]
9+
10+
source_file="res://audio/hello_jp.wav"
11+
dest_files=["res://.godot/imported/hello_jp.wav-c7c916ef924fa85620d3858f227d094f.sample"]
12+
13+
[params]
14+
15+
force/8_bit=false
16+
force/mono=false
17+
force/max_rate=false
18+
force/max_rate_hz=44100
19+
edit/trim=false
20+
edit/normalize=false
21+
edit/loop_mode=0
22+
edit/loop_begin=0
23+
edit/loop_end=-1
24+
compress/mode=0

gui/translation/audio/hello_ru.wav

94.7 KB
Binary file not shown.
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[remap]
2+
3+
importer="wav"
4+
type="AudioStreamWAV"
5+
uid="uid://dkuqg8u4fid5m"
6+
path="res://.godot/imported/hello_ru.wav-490e2b267af12af16807f2bf3de6d995.sample"
7+
8+
[deps]
9+
10+
source_file="res://audio/hello_ru.wav"
11+
dest_files=["res://.godot/imported/hello_ru.wav-490e2b267af12af16807f2bf3de6d995.sample"]
12+
13+
[params]
14+
15+
force/8_bit=false
16+
force/mono=false
17+
force/max_rate=false
18+
force/max_rate_hz=44100
19+
edit/trim=false
20+
edit/normalize=false
21+
edit/loop_mode=0
22+
edit/loop_begin=0
23+
edit/loop_end=-1
24+
compress/mode=0

gui/translation/flag_japan.png

-857 Bytes
Binary file not shown.

gui/translation/flag_spain.png

-2.56 KB
Binary file not shown.

gui/translation/flag_uk.png

-3.71 KB
Binary file not shown.

gui/translation/font/droid_sans.tres

-12
This file was deleted.
File renamed without changes.

gui/translation/font/DroidSans.ttf.import gui/translation/fonts/DroidSans.ttf.import

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
importer="font_data_dynamic"
44
type="FontFile"
5-
uid="uid://33p1pmbcp0bh"
6-
path="res://.godot/imported/DroidSans.ttf-ba789e8a8b60473207799201d8a90bb4.fontdata"
5+
uid="uid://qaejxgrojp2d"
6+
path="res://.godot/imported/DroidSans.ttf-f4f3e617929333a8a3b131725141d728.fontdata"
77

88
[deps]
99

10-
source_file="res://font/DroidSans.ttf"
11-
dest_files=["res://.godot/imported/DroidSans.ttf-ba789e8a8b60473207799201d8a90bb4.fontdata"]
10+
source_file="res://fonts/DroidSans.ttf"
11+
dest_files=["res://.godot/imported/DroidSans.ttf-f4f3e617929333a8a3b131725141d728.fontdata"]
1212

1313
[params]
1414

1515
Rendering=null
1616
antialiasing=1
1717
generate_mipmaps=false
18+
disable_embedded_bitmaps=true
1819
multichannel_signed_distance_field=false
1920
msdf_pixel_range=8
2021
msdf_size=48

gui/translation/font/DroidSansArabic.ttf.import gui/translation/fonts/DroidSansArabic.ttf.import

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
importer="font_data_dynamic"
44
type="FontFile"
5-
uid="uid://c7ujio1oqntre"
6-
path="res://.godot/imported/DroidSansArabic.ttf-da8dabd885d494269ba77c8d78d8ed5b.fontdata"
5+
uid="uid://b6jt1itr5jreh"
6+
path="res://.godot/imported/DroidSansArabic.ttf-e3dcbe0c4bc0f3f609a01ac9b0b2d1d4.fontdata"
77

88
[deps]
99

10-
source_file="res://font/DroidSansArabic.ttf"
11-
dest_files=["res://.godot/imported/DroidSansArabic.ttf-da8dabd885d494269ba77c8d78d8ed5b.fontdata"]
10+
source_file="res://fonts/DroidSansArabic.ttf"
11+
dest_files=["res://.godot/imported/DroidSansArabic.ttf-e3dcbe0c4bc0f3f609a01ac9b0b2d1d4.fontdata"]
1212

1313
[params]
1414

1515
Rendering=null
1616
antialiasing=1
1717
generate_mipmaps=false
18+
disable_embedded_bitmaps=true
1819
multichannel_signed_distance_field=false
1920
msdf_pixel_range=8
2021
msdf_size=48

gui/translation/font/DroidSansFallback.ttf.import gui/translation/fonts/DroidSansFallback.ttf.import

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
importer="font_data_dynamic"
44
type="FontFile"
5-
uid="uid://xesv5idkrqcd"
6-
path="res://.godot/imported/DroidSansFallback.ttf-9bc560676e9de93a3474250e8f345fde.fontdata"
5+
uid="uid://cdrxhlo8nqckh"
6+
path="res://.godot/imported/DroidSansFallback.ttf-fefd6276707493f1293e2a65efe0de0d.fontdata"
77

88
[deps]
99

10-
source_file="res://font/DroidSansFallback.ttf"
11-
dest_files=["res://.godot/imported/DroidSansFallback.ttf-9bc560676e9de93a3474250e8f345fde.fontdata"]
10+
source_file="res://fonts/DroidSansFallback.ttf"
11+
dest_files=["res://.godot/imported/DroidSansFallback.ttf-fefd6276707493f1293e2a65efe0de0d.fontdata"]
1212

1313
[params]
1414

1515
Rendering=null
1616
antialiasing=1
1717
generate_mipmaps=false
18+
disable_embedded_bitmaps=true
1819
multichannel_signed_distance_field=false
1920
msdf_pixel_range=8
2021
msdf_size=48

gui/translation/font/DroidSansHebrew.ttf.import gui/translation/fonts/DroidSansHebrew.ttf.import

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
importer="font_data_dynamic"
44
type="FontFile"
5-
uid="uid://cft2167j0ba27"
6-
path="res://.godot/imported/DroidSansHebrew.ttf-2fc88dbe58ef638a09561323f2a293d1.fontdata"
5+
uid="uid://7bhkit5l8dka"
6+
path="res://.godot/imported/DroidSansHebrew.ttf-12677dba89ba8356d90dbb4569825058.fontdata"
77

88
[deps]
99

10-
source_file="res://font/DroidSansHebrew.ttf"
11-
dest_files=["res://.godot/imported/DroidSansHebrew.ttf-2fc88dbe58ef638a09561323f2a293d1.fontdata"]
10+
source_file="res://fonts/DroidSansHebrew.ttf"
11+
dest_files=["res://.godot/imported/DroidSansHebrew.ttf-12677dba89ba8356d90dbb4569825058.fontdata"]
1212

1313
[params]
1414

1515
Rendering=null
1616
antialiasing=1
1717
generate_mipmaps=false
18+
disable_embedded_bitmaps=true
1819
multichannel_signed_distance_field=false
1920
msdf_pixel_range=8
2021
msdf_size=48

gui/translation/font/DroidSansJapanese.ttf.import gui/translation/fonts/DroidSansJapanese.ttf.import

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
importer="font_data_dynamic"
44
type="FontFile"
5-
uid="uid://rdmplfeo1mfc"
6-
path="res://.godot/imported/DroidSansJapanese.ttf-de3fc871b57fb078f93cf2bf5d96545a.fontdata"
5+
uid="uid://b74c6j1be4nyv"
6+
path="res://.godot/imported/DroidSansJapanese.ttf-70e19a56601aacaaf5d6d308c2567f75.fontdata"
77

88
[deps]
99

10-
source_file="res://font/DroidSansJapanese.ttf"
11-
dest_files=["res://.godot/imported/DroidSansJapanese.ttf-de3fc871b57fb078f93cf2bf5d96545a.fontdata"]
10+
source_file="res://fonts/DroidSansJapanese.ttf"
11+
dest_files=["res://.godot/imported/DroidSansJapanese.ttf-70e19a56601aacaaf5d6d308c2567f75.fontdata"]
1212

1313
[params]
1414

1515
Rendering=null
1616
antialiasing=1
1717
generate_mipmaps=false
18+
disable_embedded_bitmaps=true
1819
multichannel_signed_distance_field=false
1920
msdf_pixel_range=8
2021
msdf_size=48
File renamed without changes.

gui/translation/font/DroidSansThai.ttf.import gui/translation/fonts/DroidSansThai.ttf.import

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
importer="font_data_dynamic"
44
type="FontFile"
5-
uid="uid://ctmwkt7kh6cst"
6-
path="res://.godot/imported/DroidSansThai.ttf-91e10bcf58a298496a7fd92e1d4cd8c4.fontdata"
5+
uid="uid://t73gcvmo33on"
6+
path="res://.godot/imported/DroidSansThai.ttf-136cea21d69e1da7eb0a603f8d91fa3a.fontdata"
77

88
[deps]
99

10-
source_file="res://font/DroidSansThai.ttf"
11-
dest_files=["res://.godot/imported/DroidSansThai.ttf-91e10bcf58a298496a7fd92e1d4cd8c4.fontdata"]
10+
source_file="res://fonts/DroidSansThai.ttf"
11+
dest_files=["res://.godot/imported/DroidSansThai.ttf-136cea21d69e1da7eb0a603f8d91fa3a.fontdata"]
1212

1313
[params]
1414

1515
Rendering=null
1616
antialiasing=1
1717
generate_mipmaps=false
18+
disable_embedded_bitmaps=true
1819
multichannel_signed_distance_field=false
1920
msdf_pixel_range=8
2021
msdf_size=48

gui/translation/LICENSE.DroidSans.txt gui/translation/fonts/LICENSE.DroidSans.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
55
You may obtain a copy of the License at
66

7-
http://www.apache.org/licenses/LICENSE-2.0
7+
http://www.apache.org/licenses/LICENSE-2.0
88

99
Unless required by applicable law or agreed to in writing, software
1010
distributed under the License is distributed on an "AS IS" BASIS,

gui/translation/fonts/droid_sans.tres

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[gd_resource type="FontFile" load_steps=7 format=3 uid="uid://b0887xnwnkgju"]
2+
3+
[ext_resource type="FontFile" uid="uid://b6jt1itr5jreh" path="res://fonts/DroidSansArabic.ttf" id="1"]
4+
[ext_resource type="FontFile" uid="uid://cdrxhlo8nqckh" path="res://fonts/DroidSansFallback.ttf" id="2"]
5+
[ext_resource type="FontFile" uid="uid://7bhkit5l8dka" path="res://fonts/DroidSansHebrew.ttf" id="3"]
6+
[ext_resource type="FontFile" uid="uid://b74c6j1be4nyv" path="res://fonts/DroidSansJapanese.ttf" id="4"]
7+
[ext_resource type="FontFile" uid="uid://t73gcvmo33on" path="res://fonts/DroidSansThai.ttf" id="5"]
8+
[ext_resource type="FontFile" uid="uid://qaejxgrojp2d" path="res://fonts/DroidSans.ttf" id="6"]
9+
10+
[resource]
11+
fallbacks = Array[Font]([ExtResource("6"), ExtResource("1"), ExtResource("2"), ExtResource("3"), ExtResource("4"), ExtResource("5")])
12+
face_index = null
13+
embolden = null
14+
transform = null
15+
cache/0/16/0/ascent = 0.0
16+
cache/0/16/0/descent = 0.0
17+
cache/0/16/0/underline_position = 0.0
18+
cache/0/16/0/underline_thickness = 0.0
19+
cache/0/16/0/scale = 1.0
20+
cache/0/16/0/glyphs/0/advance = Vector2(0, 0)
21+
cache/0/16/0/glyphs/0/offset = Vector2(0, 0)
22+
cache/0/16/0/glyphs/0/size = Vector2(0, 0)
23+
cache/0/16/0/glyphs/0/uv_rect = Rect2(0, 0, 0, 0)
24+
cache/0/16/0/glyphs/0/texture_idx = -1
25+
cache/0/16/0/kerning_overrides/16/0 = Vector2(0, 0)
26+
cache/0/16/0/kerning_overrides/50/0 = Vector2(0, 0)
27+
cache/0/50/0/ascent = 0.0
28+
cache/0/50/0/descent = 0.0
29+
cache/0/50/0/underline_position = 0.0
30+
cache/0/50/0/underline_thickness = 0.0
31+
cache/0/50/0/scale = 1.0
32+
cache/0/50/0/kerning_overrides/16/0 = Vector2(0, 0)
33+
cache/0/50/0/kerning_overrides/50/0 = Vector2(0, 0)

gui/translation/hello_en.wav.import

-24
This file was deleted.

gui/translation/hello_es.wav.import

-24
This file was deleted.

0 commit comments

Comments
 (0)