Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GUI Translation demo for 4.0 #930

Merged
merged 2 commits into from
Apr 12, 2024
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
32 changes: 27 additions & 5 deletions gui/translation/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
# GUI Translation Demo

A demo showing how Godot seamlessly enables
the use of localized resources and texts.
This is a demo of how a project can be internationalized. Translations are
created in a CSV file and then imported into Godot.

For correct display, the font used must contain the glyphs required by the
target language. See the `fonts` folder for some fonts that you can use in your
project. Godot can load system fonts as a fallback, but this is not supported on
all platforms and the different visual design of system fonts can create
inconsistencies.

Godot allows internationalized text to change automatically when the locale is
modified. Resources can also be set to internationalized alternatives and replaced
automatically on locale change. This process is known as *remapping*.

Both CSV and gettext (PO/POT) approaches are showcased. Use the button in the
bottom-right corner to switch between the two approaches.

The resouce remapping process with PO is the same with CSV. The in-game text translation
process is also the same – use keys to fetch the appropriate translation.

The main difference between PO files and CSV files is the way both of them store
the translated data in their files. Have a look at the `translations/po`
and `translations/csv` folders to see the files involved.

See [Internationalizing games](https://docs.godotengine.org/en/latest/tutorials/i18n/internationalizing_games.html)
and [Localization using gettext](https://docs.godotengine.org/en/latest/tutorials/i18n/localization_using_gettext.html)
for more information.

Language: GDScript

Renderer: Compatibility

Check out this demo on the asset library: https://godotengine.org/asset-library/asset/134

## Screenshots

![Screenshot](screenshots/translation.png)
![Screenshot](screenshots/translation.webp)
File renamed without changes.
24 changes: 24 additions & 0 deletions gui/translation/audio/hello_en.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://ciept8j0x21to"
path="res://.godot/imported/hello_en.wav-2eea592f221b07e3c37c5477c1da8173.sample"

[deps]

source_file="res://audio/hello_en.wav"
dest_files=["res://.godot/imported/hello_en.wav-2eea592f221b07e3c37c5477c1da8173.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0
File renamed without changes.
24 changes: 24 additions & 0 deletions gui/translation/audio/hello_es.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://dd4xk00uh27hj"
path="res://.godot/imported/hello_es.wav-0b3ee7fc19ef7ac4822f3f3dc177c570.sample"

[deps]

source_file="res://audio/hello_es.wav"
dest_files=["res://.godot/imported/hello_es.wav-0b3ee7fc19ef7ac4822f3f3dc177c570.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0
File renamed without changes.
24 changes: 24 additions & 0 deletions gui/translation/audio/hello_jp.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://3tnymbrsqo0w"
path="res://.godot/imported/hello_jp.wav-c7c916ef924fa85620d3858f227d094f.sample"

[deps]

source_file="res://audio/hello_jp.wav"
dest_files=["res://.godot/imported/hello_jp.wav-c7c916ef924fa85620d3858f227d094f.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0
Binary file added gui/translation/audio/hello_ru.wav
Binary file not shown.
24 changes: 24 additions & 0 deletions gui/translation/audio/hello_ru.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://dkuqg8u4fid5m"
path="res://.godot/imported/hello_ru.wav-490e2b267af12af16807f2bf3de6d995.sample"

[deps]

source_file="res://audio/hello_ru.wav"
dest_files=["res://.godot/imported/hello_ru.wav-490e2b267af12af16807f2bf3de6d995.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=0
Binary file removed gui/translation/flag_japan.png
Binary file not shown.
Binary file removed gui/translation/flag_spain.png
Binary file not shown.
Binary file removed gui/translation/flag_uk.png
Binary file not shown.
12 changes: 0 additions & 12 deletions gui/translation/font/droid_sans.tres

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

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

[deps]

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

[params]

Rendering=null
antialiasing=1
generate_mipmaps=false
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

importer="font_data_dynamic"
type="FontFile"
uid="uid://c7ujio1oqntre"
path="res://.godot/imported/DroidSansArabic.ttf-da8dabd885d494269ba77c8d78d8ed5b.fontdata"
uid="uid://b6jt1itr5jreh"
path="res://.godot/imported/DroidSansArabic.ttf-e3dcbe0c4bc0f3f609a01ac9b0b2d1d4.fontdata"

[deps]

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

[params]

Rendering=null
antialiasing=1
generate_mipmaps=false
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

importer="font_data_dynamic"
type="FontFile"
uid="uid://xesv5idkrqcd"
path="res://.godot/imported/DroidSansFallback.ttf-9bc560676e9de93a3474250e8f345fde.fontdata"
uid="uid://cdrxhlo8nqckh"
path="res://.godot/imported/DroidSansFallback.ttf-fefd6276707493f1293e2a65efe0de0d.fontdata"

[deps]

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

[params]

Rendering=null
antialiasing=1
generate_mipmaps=false
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

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

[deps]

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

[params]

Rendering=null
antialiasing=1
generate_mipmaps=false
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

importer="font_data_dynamic"
type="FontFile"
uid="uid://rdmplfeo1mfc"
path="res://.godot/imported/DroidSansJapanese.ttf-de3fc871b57fb078f93cf2bf5d96545a.fontdata"
uid="uid://b74c6j1be4nyv"
path="res://.godot/imported/DroidSansJapanese.ttf-70e19a56601aacaaf5d6d308c2567f75.fontdata"

[deps]

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

[params]

Rendering=null
antialiasing=1
generate_mipmaps=false
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

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

[deps]

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

[params]

Rendering=null
antialiasing=1
generate_mipmaps=false
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
33 changes: 33 additions & 0 deletions gui/translation/fonts/droid_sans.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[gd_resource type="FontFile" load_steps=7 format=3 uid="uid://b0887xnwnkgju"]

[ext_resource type="FontFile" uid="uid://b6jt1itr5jreh" path="res://fonts/DroidSansArabic.ttf" id="1"]
[ext_resource type="FontFile" uid="uid://cdrxhlo8nqckh" path="res://fonts/DroidSansFallback.ttf" id="2"]
[ext_resource type="FontFile" uid="uid://7bhkit5l8dka" path="res://fonts/DroidSansHebrew.ttf" id="3"]
[ext_resource type="FontFile" uid="uid://b74c6j1be4nyv" path="res://fonts/DroidSansJapanese.ttf" id="4"]
[ext_resource type="FontFile" uid="uid://t73gcvmo33on" path="res://fonts/DroidSansThai.ttf" id="5"]
[ext_resource type="FontFile" uid="uid://qaejxgrojp2d" path="res://fonts/DroidSans.ttf" id="6"]

[resource]
fallbacks = Array[Font]([ExtResource("6"), ExtResource("1"), ExtResource("2"), ExtResource("3"), ExtResource("4"), ExtResource("5")])
face_index = null
embolden = null
transform = null
cache/0/16/0/ascent = 0.0
cache/0/16/0/descent = 0.0
cache/0/16/0/underline_position = 0.0
cache/0/16/0/underline_thickness = 0.0
cache/0/16/0/scale = 1.0
cache/0/16/0/glyphs/0/advance = Vector2(0, 0)
cache/0/16/0/glyphs/0/offset = Vector2(0, 0)
cache/0/16/0/glyphs/0/size = Vector2(0, 0)
cache/0/16/0/glyphs/0/uv_rect = Rect2(0, 0, 0, 0)
cache/0/16/0/glyphs/0/texture_idx = -1
cache/0/16/0/kerning_overrides/16/0 = Vector2(0, 0)
cache/0/16/0/kerning_overrides/50/0 = Vector2(0, 0)
cache/0/50/0/ascent = 0.0
cache/0/50/0/descent = 0.0
cache/0/50/0/underline_position = 0.0
cache/0/50/0/underline_thickness = 0.0
cache/0/50/0/scale = 1.0
cache/0/50/0/kerning_overrides/16/0 = Vector2(0, 0)
cache/0/50/0/kerning_overrides/50/0 = Vector2(0, 0)
24 changes: 0 additions & 24 deletions gui/translation/hello_en.wav.import

This file was deleted.

24 changes: 0 additions & 24 deletions gui/translation/hello_es.wav.import

This file was deleted.

Loading