How to make proper module translations in Drupal 8? - drupal-modules

I have to prepare modules translations, but the documentation is not helping me.
I know i can use *.pot files, but i can't fully understand how dupal is managing translations.
If i add translations/example.pot drupal will take care of everything else?

First modify module_name.info.yml add:
'interface translation project': block_example
'interface translation server pattern': modules/examples/%project/translations/%language.po*
Then create in your module directory folder translations.
Add translations/language.po files, where you will store translations.
language.po:
msgid "your id to translate"
msgstr "translations test"
template.html.twig:
<p>{% trans %}your id to translate{% endtrans %}</p>
Then go to your Drupal admin page Configuration/User interface translation, there you can filtr your msgid and see already translated files.
You may have to use IMPORT {just upload .po file}
Translations are imported automatically when you install your module.

Related

How do I enable translation to other languages in Openstack Horizon?

I am tasked to enable different languages in Openstack Horizon.
I am working on a horizon page built on top of dev stack. The Horizon page is pulled from here: https://github.com/openstack/horizon.
I want to enable translation to different languages in Horizon.
I tried to follow this documentation: https://docs.openstack.org/horizon/latest/contributor/topics/translation.html
This is an example of my code, I am trying to translate this phrase: “API Access” found in the panel on the main page :
Before editing the code, I saw that there is a corresponding translated message in openstack_dashboard/locale/zh_CN/LC_MESSAGES/django.po:
msgid "API Access"
msgstr "访问API"
This is what I did:
Firstly, In openstack_dashboard/dashboards/project/api_access/panel.py, I edited name = _("API Access") to name=pgettext("API Access", "API Access"):
from django.utils.translation import pgettext
import horizon
class ApiAccess(horizon.Panel):
name = pgettext("API Access","API Access")
slug = 'api_access'
Secondly, I ran tox -e manage -- extract_messages in the main openstack/horizon folder
Thirdly, I ran tox -e manage -- update_catalog in the main openstack/horizon folder
After I run it, this following keyword "API Access" is still not translated.
(i.e. I started horizon, went to settings, and change the language to zh-cn. But the word "API Access" is still in English.)
Not sure if this is helpful:
In openstack_dashboard/locale/Django.pot, I see this:
#: openstack_dashboard.dashboards/project/api_access/panel.py:22
msgctxt "API Access"
msgid "API Access"
msgstr ""
Grateful to anyone who can help me solve this translation issue.
Nevermind, I manage to fix it by switching to clean branch and just follow the documentation!

Autodesk Forge: Industrial Construction Demo bucket not working

I have cloned the Industrial Construction Demo code https://github.com/petrbroz/forge-industrial-construction but I am having issues with the 'bucket-name'.
In the launch file you need to specify "FORGE_BUCKET": "" instead of the usual URN.
I have written the name of the bucket that contains my file but it does not work. I have tried debugging it but still no luck.
There is no exemplary bucket or files, so I would really like to know:
-What do I need to put in as the bucket name?
-What files need to be in the bucket?
-What file types?
-Any extra information to help me figure out why it isnt working.
Many thanks,
Poppy
My apologies, I haven't explained this in the code sample very well. The demo requires files in Forge to be named in a specific way. I have just updated the README with more details: https://github.com/petrbroz/forge-industrial-construction.

In Windows Node.js fs.readdirSync With Users Folders etc

I've been developing an nw.js project and use node.js file system functions in it as normal. In my application there is a file manager and I list folders and files according to user navigation. In Windows, for example, if I scan drive C: I get the Turkish named folder "Kullanıcılar" as "Users". I know it's real name in operating system is "Users" and just seen on the screen according to Languages. I can replace names of such folders when dispaying in my file manager but I'm searching for better solution if exists. Thanks in advance.
There's an SO answer here that reads the localized name of a folder in C# using the SHGetFileInfo function which might help you along.
Now I know you didn't ask, but in case you want to know where the information is stored... It's within the directory, in the Desktop.ini file.
For instance, my Windows 10 installation has this in it for "Users":
[.ShellClassInfo]
LocalizedResourceName=#%SystemRoot%\system32\shell32.dll,-21813
And this for the Images folder within my user folder (bringing this up to show you the additional keys):
[.ShellClassInfo]
LocalizedResourceName=#%SystemRoot%\system32\shell32.dll,-21779
InfoTip=#%SystemRoot%\system32\shell32.dll,-12688
IconResource=%SystemRoot%\system32\imageres.dll,-113
IconFile=%SystemRoot%\system32\shell32.dll
IconIndex=-236
The #%SystemRoot%\system32\shell32.dll,-21813 points to having to read the MUI (multilingual user interface) resources, key 21813 for the given file (presumably the # means that it's in this file, not this literal value, but don't quote me on that). %SystemRoot% is an environment variable that points to the Windows directory.
The actual MUI files and their locations are handled by Windows (see the MSDN link above), but we'll just happen to handily know that the MUI file for the US English localization of shell32.dll is system32\en-US\shell32.dll.mui.
Opening up that file with Resource Hacker, we can search for 21813 -- and voila! We can find STRINGTABLE resource #1364 that contains:
[...snip...]
21812, "Extras and Upgrades"
21813, "Users"
21814, "Saved Games"
[...snip...]
I unfortunately don't have tr-TR/shell32.dll.mui available, so you'll just have to trust me that you'd find the Kullanıcılar string there.

Step to translate Joomla component

I've created an administrator component for Joomla 2.5 recently (in French), and not knowing how to proceed to translate it in English and German, I was wondering if someone could help me understanding the process.
Indeed, I think I understood that I need to format my strings such as :
JText::_( 'mystring' )
Then that I create .ini files, but I don't know where to create them, what they should contain, if it exists a tool like PoEdit that could suit etc. So if you have any idea how I should proceed...
Thank's guys !
In the "language" directory at the root of your website, you create the directories and files :
administration/language/en-GB/en-GB.com_yourcomponentname.ini
administration/language/fr-FR/fr-FR.com_yourcomponentname.ini
administration/language/de-DE/de-DE.com_yourcomponentname.ini
You translate each of them. I am not sure, you need a tool to do that.
And I don't know if it exists a PoEdit plugin to help you to do that too...
Your ini files look like the others that already exist in the language directories :
COM_ADMIN="Informations système"
COM_ADMIN_ALPHABETICAL_INDEX="Index alphabétique"
COM_ADMIN_CACHE_DIRECTORY="(Répertoire cache)"
Then in your views, to call a translated string :
JText::_( 'COM_ADMIN' )
This function will look for the value of COM_ADMIN in the ini file.
The loaded ini file will be the language the user has chosen, and if a translation doesn't exist, then it will load the value of the default language (chosen in administration panel).
Then if this key doesn't exist in any of these ini file, they the key is displayed.
To package your archive :
In install.xml, add these lines :
<administration>
<!-- Directory and file stuff -->
<languages folder="language/admin">
<language tag="en-GB">en-GB/en-GB.com_yourcomponentname.ini</language>
<language tag="fr-FR">fr-FR/fr-FR.com_yourcomponentname.ini</language>
<language tag="de-DE">de-DE/de-DE.com_yourcomponentname.ini</language>
</languages>
</administration>
And add the translation files in the language/admin directory.

Using a Twig Extension

I am trying to use teh Twig i18n Extension.
As far as I can tell the file I need is here:
https://github.com/fabpot/Twig-extensions/blob/master/lib/Twig/Extensions/Extension/I18n.php
Now I am not quite sure where to save this file
I have Twig in a folder called includes/lib (/includes/lib/Twig). I see a folder Extension under Twig. Do I save it here?
After I save it, do I need to do a "require_once" to the file or will Twig_Autoloader do the job for me?
I am not using Symfony2
Thanks
Craig
Here is the complete answer that worked for me:
Copy the file in Twig-Verzeichnis (extract i18n.zip in Twig).
For the I18n extension it would be Twig/Extensions/Extension/I18n.php
Eventually add other files requred by I18n. You will see what these are by the error messages that come. I had to add "Twig/Extensions/Node/Trans.php" and "Twig/Extensions/TokenParser/Trans.php".
In your config file add the following:
// Set language to German
putenv('LC_ALL=de_DE');
setlocale(LC_ALL, 'de_DE');
// Specify location of translation tables
bindtextdomain("project_de_DE", "./locale");
// Choose domain
textdomain("projectl_de_DE");
Register the Twig Extension
$twig->addExtension(new Twig_Extensions_Extension_I18n());
Create the directory locale/de_DE/LC_MESSAGES
Create the PO file (the easisest is to have a sample file to start from)
Open the file in a normal text editor (be sure to use utf-8 encoding) and start translating
Open the PO-Datei with PoEdit (www.poedit.net/)
Save to locale/de_DE/LC_MESSAGES (a MO-Datei will be created).
Add the translation to the appropriate places in the Twig-Template with
{% trans 'Text in the original language' %}`
You need to register this extension with Twig:
$twig->addExtension(new Twig_Extensions_Extension_I18n());
If your installation is configured correctly, the autoloader should do the job of including the file. If not, you could include the file manually or make the installation with composer.
It seems the "proper" way to install these extensions without Composer is as follows:
Download a release from https://github.com/fabpot/Twig-extensions/releases
Copy the contents of the lib/ directory somewhere to your project
include the file .../Twig/Extensions/Autoloader.php
Register autoloader: Twig_Extensions_Autoloader::register();
Continue as explained in the doc: http://twig.sensiolabs.org/doc/extensions/i18n.html

Resources