Jump to content

Changes in "How to add a language"


Nico Knoll
 Share

Recommended Posts

Hey,

I think if you're a new user to Processwire it's really complicated to understand how to install a new language. I've got a couple of ideas how to optimize this:

Better Description: It would be important to show at least a link to a documentary (for example: https://processwire.com/api/multi-language-support/) and add some screenshots to it. So that you get a step by step tutorial. Additonally I would add a description to the "Language Translation field" on how to get the language files (link to: http://modules.processwire.com/categories/language-pack/)

Instant install: Another way to add languages could be the Textpattern way. But I'm not sure where to place this. In the module->new section? After clicking "add new" in the setup->languages page (that's the way I would prefer. And at the bottom a link "You're language doesn't exists? Create it now!")? Or somewhere else?install-admin-lang_1100x830.png

What do you think about this? And what are your experiences with adding a new language for the first time?

/ Nico

  • Like 2
Link to comment
Share on other sites

So I spent the last couple of hours in creating a module which imitates the Textpattern thing. Take a look.

LanguageInstantInstall.module

(You have to go to Setup -> Languages and add a new language). 

post-140-0-66968100-1397917432_thumb.png

It's not completely finished (a function to update, etc. will follow) but it does what it has to do :)

What do you think?

/ nico

  • Like 11
Link to comment
Share on other sites

I love it. Not at the position to test this (on holidays), but languages are not always natural languages. We have used pw language support for client specific manuals for example. Does this module also allow own languages?

  • Like 1
Link to comment
Share on other sites

I've looked through several of the language packs under the module repo but I can't find out where the language names shown in the image below are defined. Can anyone point me in the right direction?

post-465-0-47352800-1398443559_thumb.png

Update: Are these fields derived from the module's class name by any chance?

Edited by netcarver
Link to comment
Share on other sites

Ok, I found that they are using the class name.
 
I think the Japanese and Chinese entries would be better shown in their own scripts - 日本語 [JS: \u65E5\u672C\u8A9E] and 中文(简体) [JS:\u4E2D\u6587(\u7B80\u4F53)] - respectively. Will PW or PHP choke on these if they were renamed at some point in the future? I'm not sure they will, as some of the languages are currently using unicode points from their own scripts.

Link to comment
Share on other sites

Well that's not in my hands I guess. Probably it would be smart to curate the language pack section so the classname could be adjusted if it's not in the language.

Another thing I noticed while making this is that for example the vietnamese language says "vietnamese language pack" instead of only "vietnamese".

  • Like 1
Link to comment
Share on other sites

Nico - that'll be the age old problem with not being able to moderate these without knowing the language.

Perhaps there should be a simple way to suggest language changes if you're using anything but the default? Not sure how you'd do it though (if everyone on the planet had a Github account you could click a button somewhere in the admin and open an issue on Github for that language pack right there) but I guess there should be some text along the lines of "this language pack was created by a third party author. If you have any change requests you can contact them <here>".

Assuming it doesn't already say something like that of course - I've not needed to install one myself :)

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Nico, tested out here and it works great. Thanks for making this. 

Just a few minor suggestions:

1. Your 'autoload' selector in getModuleInfo() works well, but might benefit from being more specific, like "template=admin, name=languages". 

2. Your hooks to ProcessPageType might also benefit from being more specific, i.e. ProcessLanguages rather than ProcessPageType. 

3. Rather than hard-coding the modules directory API key and base URL, you might want to pull it from the ProcessModule module, as it's possible for these things to change over time. Here's how you could grab them:

$data = $this->modules->getModuleConfigData('ProcessModule'); 
$apikey = isset($data['serviceKey']) ? $data['serviceKey'] : 'pw231';
$baseUrl = isset($data['serviceUrl']) ? $data['serviceUrl'] : 'http://modules.processwire.com/export-json/';

Note that above is falling back to hard coded values just in case of an older PW version... not sure that's necessary (I don't remember when these configuration values were added to the core). 

4. In your request to the modules directory web service, append "&category=language-pack" in the URL so that your results are limited only to language packs. Don't worry, you didn't miss this before, I just added the category filter option to the service. :)

5. Your module has downloadFile() and removeDir() methods that duplicate methods already available in the core. Basically, you can save yourself some code here if you want to. See /wire/core/Functions.php. 

6. Your module is using ZipArchive. You might find it saves time and code to use the core's built-in wireUnzipFile($file, $destination); method, also in /wire/core/Functions.php

7. In your module's getModuleInfo() method it refers to version 010. Change that to just 10. The leading 0 will make PHP think it's an octal number or something.

  • Like 5
Link to comment
Share on other sites

Hey, thanks for this great answer.

1. I added your addition.

2. It's ProcessLanguage (without s) (ProcessLanguages wouldn't work) :)

3. Included it.

4. Added it.

5. I'm not sure which function can replace downloadFile...

6. Integrated.

7. changed it and updated it to 1.0.0

  • Like 4
Link to comment
Share on other sites

Hi Nico, looks nice and does it's job.

What about a check if already any additional language exists? In my test installation I can additionally install de-de although german is already installed.

Hmm, but on the other side... most people will use this from the start in a fresh installation, so there's no problem.

BTW: typo on your blog-post. handeling --> handling

Link to comment
Share on other sites

Once again I have to ask: Why is this a Process module?

There's nothing in there that makes this should be a Process module. All it will do is clutter the process select list on admin pages for no reason.

The version, as Ryan mentioned, should be 10 not 010. Leading zero's will make it read as octal, and octal 010 is 8.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...