Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

Importowanie tłumaczeń

Gry i umiędzynarodowienie

The gaming community isn't monolingual or monocultural. It's made up of many different languages and cultures - just like the Godot community! If you want to allow players to experience your game in their language, one of things you'll need to provide is text translations, which Godot supports via internationalized text.

W zwykłych aplikacjach stacjonarnych lub telefonicznych tekst jest zazwyczaj umieszczany w plikach zasobów (lub plikach .po dla projektów GNU). W grach można jednak wykorzystywać tekst o kilka rzędów wielkości większy niż w aplikacjach, dlatego muszą one obsługiwać wydajne metody radzenia sobie z ładowaniem tekstu wielojęzycznego.

Istnieją dwa podejścia do tworzenia wielojęzycznych gier i aplikacji językowych. Oba oparte są na systemie key:value. Pierwszy to użycie jednego z języków jako klucza (zazwyczaj angielskiego), drugi to użycie określonego identyfikatora. Pierwsze podejście jest prawdopodobnie łatwiejsze do rozwoju, jeśli gra jest wydawana najpierw w języku angielskim, a później w innych językach, ale jest koszmarem, jeśli pracuje się z wieloma językami w tym samym czasie.

Ogólnie rzecz biorąc, w grach stosuje się drugie podejście, a dla każdego łańcucha używany jest unikalny identyfikator. Pozwala to na skorygowanie tekstu w trakcie jego tłumaczenia na inne języki. Unikatowym identyfikatorem może być numer, łańcuch lub łańcuch z numerem.

Informacja

Jeśli potrzebujesz bardziej wydajnego formatu pliku, Godot obsługuje również ładowanie tłumaczeń napisanych w formacie gettext .po. Zobacz Localization using gettext po szczegóły.

Format tłumaczenia

Aby dopełnić obrazu i umożliwić wydajną obsługę tłumaczeń, Godot posiada specjalny importer, który może odczytywać pliki CSV. Większość edytorów arkuszy kalkulacyjnych może eksportować do tego formatu, więc jedynym wymogiem jest, aby pliki były w środku specjalnie ułożone. Pliki CSV muszą być zapisane z kodowaniem UTF-8 bez znacznika kolejności bajtów.

CSV files must be formatted as follows:

keys

<lang1>

<lang2>

<langN>

KEY1

string

string

string

KEY2

string

string

string

KEYN

string

string

string

The "lang" tags must represent a language, which must be one of the valid locales supported by the engine. The "KEY" tags must be unique and represent a string universally (they are usually in uppercase, to differentiate from other strings). These keys will be replaced at runtime by the matching translated string. Note that the case is important, "KEY1" and "Key1" will be different keys. The top-left cell is ignored and can be left empty or having any content. Here's an example:

keys

en

es

ja

GREET

Cześć kolego!

Hola, amigo!

こんにちは

ASK

Jak się masz?

Jak się masz?

元気ですか

BYE

Goodbye

Żegnaj

Żegnaj

QUOTE

"Hello" said the man.

"Hola" dijo el hombre.

「こんにちは」男は言いました

The same example is shown below as a comma-separated plain text file, which should be the result of editing the above in a spreadsheet. When editing the plain text version, be sure to enclose with double quotes any message that contains commas, line breaks or double quotes, so that commas are not parsed as delimiters, line breaks don't create new entries and double quotes are not parsed as enclosing characters. Be sure to escape any double quotes a message may contain by preceding them with another double quote. Alternatively, you can select another delimiter than comma in the import options.

keys,en,es,ja
GREET,"Hello, friend!","Hola, amigo!",こんにちは
ASK,How are you?,Cómo está?,元気ですか
BYE,Goodbye,Adiós,さようなら
QUOTE,"""Hello"" said the man.","""Hola"" dijo el hombre.",「こんにちは」男は言いました

CSV importer

Godot domyślnie będzie traktował pliki CSV jako tłumaczenia. Zaimportuje je i wygeneruje jedną lub więcej skompresowanych plików źródłowych tłumaczenia obok tego.

Importowanie doda także tłumaczenie do listy tłumaczeń w chwili wczytywania gry, ustalonych w project.godot (lub ustawieniach projektu). Godot pozwala także na wczytywanie i usuwanie tłumaczeń w czasie działania programu.

Select the .csv file and access the Import dock to define import options. You can toggle the compression of the imported translations, and select the delimiter to use when parsing the CSV file.

../../_images/import_csv.png

Be sure to click Reimport after any change to these options.