Contribute to the internationalization of Printoid

You can now contribute to the Printoid Project by translating the app by yourself to your native language!

You don’t have to be a developer, and you don’t need any development skills 🙂

But for convenient, easier integration and maintenance, and for tracking changes in the XML files, I have created a public repository on Github.

For your personal information, I have introduced a new Android Library called Printoid Languages. This library is now included in the Printoid project, and it contains all the resources for the internationalization of the application.

Don’t worry, the following informations looks hard to understand for a beginner with Git, but if you follow the steps in the right order, that’s very easy!

PREREQUISITES

First of all, you need to create your own Github account here ; or sign in to an existing account here.

You also need to install git on your computer. In a terminal, execute the following commands depending on your operating system.

Debian-based Linux systems

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git

Red-Hat based Linux systems

sudo yum upgrade
sudo yum install git

Mac systems

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew doctor
brew install git

Windows systems

Download git and install it: https://gitforwindows.org/

FORK AND CLONE

Creating a fork

Here is the repository of Printoid Languages on Github:

https://github.com/anthonyst91/PrintoidLanguages

Just head over to the GitHub page and click the “Fork” button. It’s just that simple. Once you’ve done that, you can use your favorite git client to clone your repository or just head straight to the command line:

# Clone your fork to your local machine 
git clone git@github.com:YOUR_USERNAME/FORKED-PROJECT.git

Keeping your fork up to date

While this isn’t an absolutely necessary step, if you plan on doing anything more than just a tiny quick fix, you’ll want to make sure you keep your fork up to date by tracking the original “upstream” repo that you forked. To do this, you’ll need to add a remote:

# Add 'upstream' repo to list of remotes
git remote add upstream https://github.com/UPSTREAM-USER/ORIGINAL-PROJECT.git

# Verify the new remote named 'upstream'
git remote -v

Whenever you want to update your fork with the latest upstream changes, you’ll need to first fetch the upstream repo’s branches and latest commits to bring them into your repository:

# Fetch from upstream remote
git fetch upstream

# View all branches, including those from upstream
git branch -va

Now, checkout your own master branch and merge the upstream repo’s master branch:

# Checkout your master branch and merge upstream
git checkout master
git merge upstream/master

If there are no unique commits on the local master branch, git will simply perform a fast-forward. However, if you have been making changes on master (in the vast majority of cases you probably shouldn’t be – see the next section, you may have to deal with conflicts. When doing so, be careful to respect the changes made upstream.

Now, your local master branch is up-to-date with everything modified upstream.

WORK ON THE TRANSLATIONS

Create a branch

Whenever you begin work, it’s important that you create a new branch. Not only is it proper git workflow, but it also keeps your changes organized and separated from the master branch so that you can easily submit and manage multiple pull requests for every task you complete.

To create a new branch and start working on it:

# Checkout the master branch - you want your new branch to come from master
git checkout master

# Create a new branch named new_translation_name (give your branch its own simple informative name)
git branch new_translation_name

# Switch to your new branch
git checkout new_translation_name

Now, go to town hacking away and making whatever changes you want to.

Update/create the translations

The resources are located in the /app/src/main/res/ folder.

  • values contains the default values, in english
  • values-fr contains the values translated in french
  • values-de contains the values translated in german
  • values-es contains the values translated in spanish
  • values-ru contains the values translated in russian
  • values-nl contains the values translated in dutch
  • values-it contains the values translated in italian
  • values-zn contains the values translated in chinese

To create the translations to a new language, you need to create a new folder in /app/src/main/res/. For example, to introduce these new languages:

  • values-it for italian translations
  • values-pt for portuguese translations
  • values-pl for polish translations

Then, copy all the xml files from an existing folder. For example:

  • if you want to translate from English to Italian, then copy the files from values to values-it
  • if you want to translate from French to Polish, then copy the files from values-fr to values-pl

Please, don’t rename the files. Keep the files name (the strings are ordered by app features).

To edit the files, you can use your favorite file editor. Please, do not try to format the code with colors/text sizes if you plan to use something like Ms Word or LibreOffice Writer 😉

Some translation examples

A basic example

In the file values/string_connect.xml :

<string name="connection_dialog_title">Connection to your server</string>
<string name="connection_dialog_message">Printoid is connecting to your server, please wait...</string>

The translation in french would look like, in values-fr/string_connect.xml :

<string name="connection_dialog_title">Connexion au serveur</string>
<string name="connection_dialog_message">Printoid se connecte à votre serveur, veuillez patienter...</string>

Please, don’t rename the resource’s names. You should only translate what’s inside the …>

An example with qualifiers

Sometimes you will find some exotic characters, such as %d, %s, %.1f. These are qualifiers, where Printoid will inject dynamic values. For example:

<string name="config_say_hello">Hello %s!</string>

should be translated in french as:

<string name="config_say_hello">Bonjour %s !</string>

so Printoid will be able to inject the username, for example: “Hello Patrick!” and “Bonjour Patrick !”

Some qualifiers also have index to order the dynamic values: %1$s, %2$s, %3%s. For example:

<string name="config_introduce_developer">The developer is %1$s, and he is %2$d.</string>

should be translated in french as:

<string name="config_introduce_developer">Le développeur s\'appelle %1$s, et il a %2$d ans.</string>

Character escapments

And, last but not least, some characters have to be escaped, such as quotes. To escape a character, you have to add a backslash in front of it.

<string name="config_introduce_developer_age">He\'s 27 years old.</string>

And for carriage returns, that’s \n :

<string name="connection_progress_dialog_message">The app is trying to communicates with your 3D printer.\nYou can drink a coffee for the next 2 seconds.</string>

SUBMIT YOUR CHANGES

Cleaning up your work

Prior to submitting your pull request, you might want to do a few things to clean up your branch and make it as simple as possible for the original repository’s maintainer to test, accept, and merge your work.

If any commits have been made to the upstream master branch, you should rebase your development branch so that merging it will be a simple fast-forward that won’t require any conflict resolution work.

# Fetch upstream master and merge with your repo's master branch
git fetch upstream
git checkout master
git merge upstream/master

# If there were any new commits, rebase your development branch
git checkout newfeature
git rebase master

Now, it may be desirable to squash some of your smaller commits down into a small number of larger more cohesive commits. You can do this with an interactive rebase:

# Rebase all commits on your development branch
git checkout 
git rebase -i master

This will open up a text editor where you can specify which commits to squash.

Submitting

Once you’ve committed and pushed all of your changes to GitHub, go to the page for your fork on GitHub, select your development branch, and click the pull request button. If you need to make any adjustments to your pull request, just push the updates to GitHub. Your pull request will automatically track the changes on your development branch and update.

Enjoy!

Then, as the developer of Printoid, I will perform some adjustments/corrections on your changes, then accept your pull request 🙂

Your changes will be integrated to Printoid Languages, and finally integrated to the Printoid main project during the next release generation!

SPECIAL THANKS

This tutorial is based on the great work of Chase Pettit (source)

Thanks a lot to all the nice contributors to this project: together we will make Printoid better!