Difference between revisions of "Translations"

From PioneerWiki
Jump to: navigation, search
(Imported from github wiki)
 
 
(15 intermediate revisions by 4 users not shown)
Line 1: Line 1:
Pioneer aims to be internationalized. To this end, there is support for multiple languages in Pioneer. This document specifies how the languages are defined, and how somebody can translate Pioneer to a new one.
+
All text in Pioneer is translatable, and the game ships with several translations. Here's everything you need to know.
  
Localization is not a current aim. The game is set in the distant future; any cultural conventions will be drawn from the fictional premise of the game.
+
== For translators ==
  
There are two translation systems. The first is for the core game engine. The second is for those parts of the game which are implemented in Lua.
+
All our translations are managed through [http://transifex.com Transifex], a free web-based translation service. To start writing translations, sign up there, using [https://www.transifex.com/signup/open-source/?join_project=pioneer this link], and then take a look at the [https://www.transifex.com/projects/p/pioneer/ Pioneer project]. You can either use the web-interface, or download the full file, and edit off line, and then re-upload.
  
==Core engine translation==
+
Changes to translations are automatically pulled into the master git repo, from transifex, twice per day, and from there to the builds when they're next run.
Pioneer selects its languages dynamically, at run time. The languages are defined in files in data/lang. They are should be named after the native name of the language (English, Deutsch, Nederlands, etc) with a <code>.txt</code> filename extension. <code>English.txt</code> should always be present. It is the master language. All other language files should be a translation of <code>English.txt</code>, and any untranslated strings will fall back to the English.
 
  
Language files should be encoded as UTF-8, and must not have a byte order marker at the start. The content of the file should look like this:
+
In Transifex you can subscribe to notifications for the languages or resources you're interested in. When new strings are added or modified, you'll be notified.
  
# This is a comment
+
If you want to translate Pioneer to an entirely new language, please [https://github.com/pioneerspacesim/pioneer/issues open an issue] on the tracker and someone will create the translation for you.
GAME_SAVED_TO
 
    "Game saved to "
 
SELECT_FILENAME_TO_LOAD
 
    Select a file to load
 
COULD_NOT_OPEN_FILENAME
 
    Could not open %path
 
  
Blank lines and lines beginning with # are ignored. All the other lines in the file are interpreted as tokens and definitions, alternately, until the end of the file.
+
English is the canonical language for Pioneer. As such, you can't directly modify the english strings through Transifex. If you want to change those, you'll need to make the change in source code hosted in git and submit a pull request like for a normal code change. However, do note that changes in english text will trigger re-translation of that string in all other languages, thus there should be a good motivation why a string is changes (e.g. spelling/grammar).
  
===Tokens===
+
Untranslated strings will use the value from the English version.
  
The token is a single word or phrase, in capitals, with underscores replacing spaces and with no punctuation. The token is the same in all languages, and uniquely identifies a translatable phrase to Pioneer.
+
You can leave comments in Transifex to help out other translators. You'll also see any notes left by the developers to help you translate a particular string.
  
===Definitions===
+
If you're a new translator and you'd like your name included in AUTHORS.txt, please let us know!
  
The definition is the translatable phrase, in whichever language is specified in the filename. Leading and trailing whitespace are ignored. The definitions are indented for legibility, but this is just for the benefit of the person working with the file, not a technical requirement.
+
For when you translate: Text within curly brace denote a varialbe name that will be substituted and should not be translated, e.g.  
  
If a translatable phrase should have a leading or trailing space, the definition must be quoted as in the example "Game saved to"' above. This practice is being superseded by tokenization, as described below. If you find a translation where word order would be wrong in your language, please raise an issue on the [https://github.com/pioneerspacesim/pioneer/issues Github issue tracker] so that it can be tokenized.
+
    "Welcome to {system}"
  
Tokenization, as in the example "Could not open %path" above, is used where a phrase will have words inserted by Pioneer. In the example, it is the name of a saved game. In others, it might be where a date or a price is used, or a character's name, a piece of equipment or a cargo type. These tokens are not the same as the main language tokens. These tokens begin with a percent sign, and if they are used adjacent to other words, they can be enclosed in braces, as in this example:
 
  
NUMBER_TONNES
 
    %{mass}t
 
  
Tokens within definitions must not be changed or translated. If the token is changed, it will stop working.
+
== For mod developers ==
  
==Lua module translation==
+
Each module gets its own translation resource, called <tt>module-foo</tt>.
===Regular translatable phrases===
 
  
Translatable phrases in Lua modules are defined as tables within Lua files. The filename is arbitrary, and is normally chosen by the script writer, who should ideally have provided translatable phrases in the English language.
+
To get at the strings for your module, do something like:
  
Languages are defined as a single Lua table, which contains each language's name as a key, and a further table as that language's dictionary. This is passed to the Translate:Add() function as a single parameter. English ''must'' be defined first, otherwise the game can crash. A simple example is as follows:
+
    local Lang = import("Lang")
 +
    local l = Lang.GetResource("module-foo")
  
Translate:Add({
+
Then you can get at the string by its token:
    English = {
 
        WELCOME = 'Welcome',
 
        ["That's beautiful"] = "That's beautiful",
 
    },
 
    Deutsch = {
 
        WELCOME = 'Willkommen',
 
        ["That's beautiful"] = 'Das ist wunderschön',
 
    }
 
})
 
  
This example adds two phrases each to the English and German languages. While a basic understanding of Lua is helpful, it shouldn't be absolutely necessary.
+
    print(l.SOME_TRANSLATED_STRING)
  
Note that tokens can be any valid Lua key value. The first style shown above, '''WELCOME''', is a simple token. The other one, '''["That's beautiful"]''', is required wherever a token contains spaces or punctuation. Using the English string as the token makes the mission code more legible.
+
While its possible to load multiple translation resources to share strings, its highly recommended that you don't do that. Stick to your own strings so that you don't have to track changes in other modules. Duplicates across resources are fine. Note that code that uses multiple resources won't be accepted into the main Pioneer repository unless you've checked it with a core developer first and it has a good reason.
  
The definitions are strings. All entries within tables in Lua should be followed by a comma. Definitions might contain tokens; some will be like the ones described in the Core Engine section above, but others might appear in curly braces like {this}. Those tokens should not be modified or translated; they are where the Lua script will insert other values.
+
Translations are [https://developer.chrome.com/extensions/i18n.html <tt>chrome.i18n</tt> JSON] files. The format is fairly simple - a JSON object with tokens as keys and values of an object with two keys, <tt>message</tt> and <tt>description</tt>. <tt>message</tt> is the text that will appear in the game, while <tt>description</tt> provides instructions for the translator that will be displayed in Transifex. [https://www.json.org/img/string.png Here] is a useful chart showing how characters are interpreted.
  
===Mission flavours===
+
If you're submitting code that requires a new language you should only include <tt>en.json</tt>. Please tag '''@impaktor''' in your pull request so they can create a new resource in Transifex and make sure a language update is done at merge. If you don't do this then you'll break the game for non-English users.
  
The Translate library also includes methods for dealing with flavours. A flavour is an alternative set of phrases for use in a bulletin board advert, or similar, used to add variety to the same mission.
+
== For core developers ==
  
Flavours are defined as a simple Lua table, and are passed to the ''Translate:AddFlavour()'' function, along with the flavour's language and the name of the module. The name of the module must not be changed, or the flavour will not be used. The flavour loader, Translate:AddFlavour, checks for errors. The first flavour to be defined must be English; all others will be checked to make sure that their structure matches that one.
+
The <tt>core</tt> resource is magical. If you add a string to it, you also need to add it to <tt>LangStrings.inc.h</tt> and recompile. It will then be available as <tt>Lang::SOME_TRANSLATED_STRING</tt>.
 
 
A flavours can be added like this:
 
 
 
Translate:AddFlavour('English','TestModule',{
 
      title = "Shill bidder wanted for auction",
 
      greeting = "Hi there.  Want to earn some quick cash?",
 
      yesplease = "Sure.  What do you need me to do?",
 
      nothanks = "No, ta - this looks a bit shady.",
 
})
 
 
 
And another:
 
 
 
Translate:AddFlavour('English','TestModule',{
 
      title = "Help me win an auction.",
 
      greeting = "Hello.  I'll pay you to place fake bids for me.  Interested?",
 
      yesplease = "Yes, I like to live dangerously.",
 
      nothanks = "No thanks; I'd rather not get arrested for fraud.",
 
})
 
 
 
The language is specified in the first line as '''English''', and after the language comes the module name, which in this example is '''testmodule'''. To add a German flavour, simply copy that structure, change the 'English' to 'Deutsch' and translate the strings between the quotes. As before, if you see tokens like {this}, do not alter them. They will be replaced by another value during the game.
 
 
 
It is not necessary to have the same number of flavours in every language. It is necessary to include all of the keys, and not to add extra ones or mis-spell them. If that happens, it will produce an error.
 
 
 
===Submitting work===
 
 
 
Ideally, translators should have an account on Github.com and should work from their own fork of the project. New languages, and modifications of existing languages, can be submitted for inclusion in Pioneer by means of a Github.com pull request.
 
 
 
If you do not wish to use Github.com, the next best solution is to submit an email formatted patch set from any other git repository.
 
 
 
If you cannot use git at all, please either email your submission to [mailto:brian@ppcis.org brian@ppcis.org], or send it to Brianetta on the Space Sim Central forum. Be sure to include your name and email address; these will be used to mark your work on the git commit log.
 

Latest revision as of 17:13, 30 June 2024

All text in Pioneer is translatable, and the game ships with several translations. Here's everything you need to know.

For translators

All our translations are managed through Transifex, a free web-based translation service. To start writing translations, sign up there, using this link, and then take a look at the Pioneer project. You can either use the web-interface, or download the full file, and edit off line, and then re-upload.

Changes to translations are automatically pulled into the master git repo, from transifex, twice per day, and from there to the builds when they're next run.

In Transifex you can subscribe to notifications for the languages or resources you're interested in. When new strings are added or modified, you'll be notified.

If you want to translate Pioneer to an entirely new language, please open an issue on the tracker and someone will create the translation for you.

English is the canonical language for Pioneer. As such, you can't directly modify the english strings through Transifex. If you want to change those, you'll need to make the change in source code hosted in git and submit a pull request like for a normal code change. However, do note that changes in english text will trigger re-translation of that string in all other languages, thus there should be a good motivation why a string is changes (e.g. spelling/grammar).

Untranslated strings will use the value from the English version.

You can leave comments in Transifex to help out other translators. You'll also see any notes left by the developers to help you translate a particular string.

If you're a new translator and you'd like your name included in AUTHORS.txt, please let us know!

For when you translate: Text within curly brace denote a varialbe name that will be substituted and should not be translated, e.g.

   "Welcome to {system}"


For mod developers

Each module gets its own translation resource, called module-foo.

To get at the strings for your module, do something like:

   local Lang = import("Lang")
   local l = Lang.GetResource("module-foo")

Then you can get at the string by its token:

   print(l.SOME_TRANSLATED_STRING)

While its possible to load multiple translation resources to share strings, its highly recommended that you don't do that. Stick to your own strings so that you don't have to track changes in other modules. Duplicates across resources are fine. Note that code that uses multiple resources won't be accepted into the main Pioneer repository unless you've checked it with a core developer first and it has a good reason.

Translations are chrome.i18n JSON files. The format is fairly simple - a JSON object with tokens as keys and values of an object with two keys, message and description. message is the text that will appear in the game, while description provides instructions for the translator that will be displayed in Transifex. Here is a useful chart showing how characters are interpreted.

If you're submitting code that requires a new language you should only include en.json. Please tag @impaktor in your pull request so they can create a new resource in Transifex and make sure a language update is done at merge. If you don't do this then you'll break the game for non-English users.

For core developers

The core resource is magical. If you add a string to it, you also need to add it to LangStrings.inc.h and recompile. It will then be available as Lang::SOME_TRANSLATED_STRING.