Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+6 votes
1.4k views
in Q2A Core by
edited by
Notes for developers only
 
As of 1.6.3, only translations for the language codes and countries listed in file https://github.com/q2a/question2answer/blob/v1.6.3/qa-include/qa-app-admin.php#L69 were able to be added by just creating a directory named the same way as the ISO code listed in that file. For example, if I wanted to add the Spanish translation I just created the directory 'qa-lang/es' and then added the translation files in there.
 
However, this approach of having hardcoded ISO codes has 2 disadvantages:
  1. It requires maintainance. In order to add a translation for a country with an ISO code not listed, it was needed to add that code in the 'qa-app-admin.php' file and then create the appropriate directory with the same name under 'qa-lang'
  2. It takes time. Newly added translations would have to wait for a new release in order to be in the core and be used without any core file modification
As of 1.7 this has changed into a more dynamic approach. Instead of the core expecting a set of given ISO codes it will get the code from directories under 'qa-lang'. That means, if there is a directory named 'qa-lang/es-AR' (which is not supported in 1.6.3) then the core will assume 'es-AR' is the language code. That value will be saved in the 'site_language' option.
 
Although this would be enough to dynamically add new languages there is one minor thing missing: its display in the combobox of the site language setting. So in order to fix this a new file need to exist which will hold the display name. This file will be treated in a similar way to the new addon 'metadata.json' files. This means it will be a json file which will hold key-value elements. One of those elements (as of 1.7.0, the only one) will have the key 'name'. The value associated to that key will be the display name. In the 'es-AR' case it would be 'Spanish - Argentina'.
 
The advantage of doing so is that not only will it be possible to support any language code and country combination but also additional metadata could be added in the future. For example, it could be possible to add data for the author of the language file or maybe its version.
 
Notes for translators and developers
 
In order to create a translation for 1.7+ you should follow these steps:
  1. Create a directory under 'qa-lang' named as the language code for your country and optionally with a country code. It is not actually required to use an ISO code but it will make things easier if the idea is to make the translation public. EG: 'qa-lang/es' or 'qa-lang/es-AR'.
  2. Copy all files from 'qa-include/lang' into the directory created in the previous step.
  3. Translate the files in the directory created in step 1.
  4. Create a the file 'metadata.json' under the directory created  in step 1. EG: 'qa-lang/es/metadata.json' or 'qa-lang/es-AR/metadata.json'.
  5. Add the following content to the file created in the previous step (of course, replace the language and country accordingly):
{
    "name": "Spanish - Argentina"
}
 
For a while, the 1.6.3 translation system will coexist with the 1.7 one but the former will eventually dissappear so it is a good idea to start new translations (or modify any current one) in a way that supports the new system.
 
You can check this GitHub repository for a real life example of a v1.7 compliant translation: https://github.com/pupi1985/q2a-spanish-translation
Q2A version: 1.7+
by
@pupi Good job.

2 Answers

+2 votes
by

Great, now it's easily possible to add pirate language to Q2A.

that be goin' t' be jolly lads

:D

+1 vote
by
Where should the translations be sent? Last time I sent to Gideon's e-mail @question2answer.org but that doesn't seem to be working anymore.
by
According to http://www.question2answer.org/addons.php#languages , the right approach is using the feedback section. I see some 1.7 translations there. I've sent the Spanish one last week. So far I got no answer either. Anyway, I bet it is just a matter of time for Gideon to process them
by
My apologies for this. The Q2A server got onto a PBL blacklist and so the messages from there weren't successfully forwarded to my mailbox. It should be fixed now and you can send translations to gideon at the Q2A domain.
...