Tuesday 27 September 2016

Using freetm.com to translate the user guide for drupal 8

This guide is divided into two parts, one for project managers who prepare the translation memories (TMs)  and adjust its settings, and for translators, who just use the prepared TMs.

Instructions for project managers:


Creating translation memory in TMX format from .po files


For this and any other drupal translation it is very useful to have a TM from Drupal core.
This can be created in two steps. First segment the .po file, that is break the big useless chunks of text consisting of many sentences into smaller chunks (sentences).

Creating segmented po file using posegment from the translate toolkit. The default source language is 'en':
posegment --language=af-ZA drupal-8.2.0-rc2.hu.po segmented.po

 After this create a tmx translation memory from the segmented .po file. The default source language is 'en'. As I understand, 2 letter ISO languages can be used with occasional sublanguage (dialect) tags appended:
po2tmx --language=af-ZA segmented.po drupal8-segmented.tmx

Setting up the freetm.com environment for translation


There is also a FAQ

Having created the Drupal core TM, we are gonna use that as a read-only TM, and we create another project specific TM that will store our translations. This way we don't mess up the Drupal core TM, and that can be reused in the future.

Click File -> TM and Glossary, and on the displaying panel click Upload and upload the Drupal core tmx memory from your local drive.





On the same panel click on Create to create a TM to be used for translation. Set the language pair and give it a name, eg. userguide. Optionally create a glossary. I think that is another very useful feature, so just go ahead and create one. In the example I have a general Drupal glossary, and a glossary created specifically for the user guide translation. Here we can add the project specific terms, eg. 'Farmer's market' - 'Termelői piac', which are irrelevant in general Drupal context.
The just uploaded Drupal 8 translation memory will be used only for reference as a read only memory. For this check its read only checkbox. We use the userguide TM to store the translations we create. Make sure its read only checkbox is unchecked. On the screenshots I made these resources active, but as far as I can see, inactive TMs and glossaries can also be shared. Inactive resources are just not used from the current account for translating files uploaded to it.




For each active TM and glossary click the Share button, and add the email addresses of the required translators, who already have registered into freetm.com.
That's it for setting up the environment.

Instructions for translators:


  • Create a user account on freetm.com. 
  • Ask your project manager to share the resources (translation memories and glossaries) with your account.

In order for freetm.com to properly segment asciidoc files, we had to remove the linebreaks from the Hungarian asciidoc files, otherwise they were incorrectly separated, and they could not be joined using the 'Expand' button. There is now also an issue to remove the 80 char limit requirement. Until it is not fixed in every language, you can try using the Hungarian untranslated source files, where the linebreaks are already removed.

  • From the File menu click Upload and upload the translatable txt files (without sentence separating linebreaks), or you can drag and drop them under the document list.
  • Assign translation memories (TMs) and glossaries to your files by making them active. In order to avoid repeating this step for every subsequently uploaded file you can set the default TMs and glossaries. For this open a file, click TMs & Glossaries tab -> Setup button. This is not straightforward, so pay attention. From my correspondence from the developers:

There are two ways to change the TM selection that correspond to two different cases, although the dialog that is opened is the same.
Selecting a file from Document Management List and using "File tab>TM&Glossary button" will only change the configuration for the selected file.
When a file is opened and you use "TMs&Glossaries tab>Setup button" you'll change the configuration of the file and the default selection of TMs that will be used from now on on the new uploaded files.

  • The UI and its many features might be daunting at first, but don't get scared, you will only need to use just a few buttons. In order to make the UI more simple, we place the necessary buttons on the Custom tab. For this on the Wordfast Anywhere tab click Setup, and then click Pandora's Box. Scroll down to no. 15. Custom tab settings, and click on the pencil icon. We placed the following frequently used buttons on our Custom tab:
    • Start/Next (Opens the next segment for translation.)
    • Close Commit (Closes the currently opened segment and saves the translation.)
    • Copy Source (Copies the source text into the target text. You can also check the 'Copy source when no TM match and no MT proposition' checkbox in Pandora's Box, then this button is not really needed.)
    • Concordance (Search the TMs for a text.)
    • Glossary Search
    • Add Term
    • Close Delete (Close the current segment, and delete the target content.)
    • Expand (Join the current segment with the next one. Does not work through linebreaks).
    • Shrink (Split the current segment into two, if the segmentation was incorrect.)
    • Copy TU (Copy Translation Unit. Hopefully this will be your best friend that copies the TM suggestions to the target.)






  • If you translate closely related languages, you might experiment with it, but otherwise I do not recommend the usage of Machine translation (MT), so in the Wordfast Anywhere menu click the Setup button, click Setup Machine Translation, and under the MyMemory tab uncheck the Use MyMemory checkbox.


And a last tip, in order to effectively translate, try using the keyboard shortcuts of the buttons. About half a year ago when I last used the tool, after a while the keyboard shortcuts stopped working. To fix this I had to close the file under translation, then I had to reopen it.


Now press Start/Next or Alt+Down, start translating and enjoy the suggestions coming from the TMs and glossaries!

Thursday 28 January 2016

Installing drupalconsole on Windows



Trying to recall, how I have installed drupalconsole on Windows. By the way, somehow I had no problems at all ;-)

On my Windows 7 system I have found two ways to install drupalconsole. Later you will need Git Bash from the Git for Windows program package to run drupalconsole, so I recommend issuing the following command in the Git Bash prompt:

curl https://drupalconsole.com/installer -L -o drupal.phar

Running the other command from Git Bash gave me the "output is not a tty" error, and created a 0 size file, but running this from a Windows command prompt worked:

php -r "readfile('https://drupalconsole.com/installer');" > drupal.phar

For the record I had PHP version 5.5.27 on my machine. At this point you can already run drupalconsole with issuing the "php drupal.phar" command, supposing the php.exe file is in your system PATH. Then you can rename the just downloaded drupal.phar file to any preferred name, eg. drupal or drupalconsole, and move it to the directory that contains your php.exe file. After this you can just type the name of your command in the Git Bash prompt, and create the configuration files. Since I have renamed my drupal.phar file to drupalconsole I use this in the example:

# Copy configuration files to user home directory:
drupalconsole init --override

Then run the next command to have drupalconsole update itself:

# Update DrupalConsole to the latest version:
drupalconsole self-update

Don't forget to always use the Git bash window to run drupalconsole.

Sunday 24 January 2016

Translating drupal's yaml and po files on freetm.com


I am trying to find a solution to translate Drupal's .po and .yml files with a computer assisted translation (CAT) tool. Recently I had to use freetm.com, which I found quite useful, but it still has its own problems. For example you can only upload 10 files at a time. With drupal core's .po file it is not a problem, but as there are many .yml files, they have to be translated in batches of 10. Freetm.com supports the translation of XLIFF files, and the translation memory can be exported in the industry standard TMX format. I used the okapi framework to convert yml to xliff. As I remember, I have used it earlier to convert po files to xliff too.

To convert yaml files to xliff, run a command like:

tikal -x hu/user.delete.yml -seg -sl EN -tl HU -oe utf8

The -sl parameter specifies the source language, -tl specifies the target language with its 2 letter code.
After finishing the translation of .xlf files with freetm.com, copy the xlf files into the same directory as the original yml files, then run a command similar to the following:

tikal -m temp/*.xlf -sl EN -tl HU -oe utf8

Don't forget to add the output encoding (-oe), without it I have received ANSI encoded files.

Sunday 6 December 2015

Using route_parameters in drupal 8 menu links

Just a reminder for anyone, how to create menu links in drupal 8 that point to the node/add/content_type page.

mymodule.add_whatever:
  title: 'Add whatever'
  description: 'Add whatever'
  route_name: node.add
  route_parameters: { node_type: 'name_of_node_type' }
  menu_name: main
  weight: 7

The code snippet above is from the mymodule.links.menu.yml file.