Jump to content

Module Language Translator Plus


kixe
 Share

Recommended Posts

I created a Modul which extends Language Translator (Core) Modul, with a select-field to choose translatable files not translated yet. But it doesn't work perfectly, because the language to be translated isn't set by default. Even if I use the Standard Language Translator,
no translated files will be listed. Even then, if I have set translation files for all my languages.

post-1246-0-31755300-1381974850_thumb.jp

If I go to setup -> language, choose a language and start to edit a translation file, the language-to-translate will be set in the system. Now I can go to the Language Translator and it looks like I had expected:

post-1246-0-40763300-1381974841_thumb.jp

Just to be clear I am not talking about the user language.

I think it would be useful either to have a Language Selector in the Module Language Translator to select the language before the files are (not) displayed, or to set a default language-to-translate, which will be displayed in the Head of Language Translator to be clear which language is in processing.

I will have a deeper look to find a solution.

1 hour later:

looks like it would work now. I initialized the modul with the users language by default, if nothing else is set (GET or SESSION)

I made an update on github.

Maybe its a better idea to make the Language-Translator a Child Page of the specific Language Page. ... or to go sleeping
Good Night ...

17.10.13
Updated the Module today with a Language Switcher and a clear headline which let you know in which language you are. Working fine on my System now.

Looks like:
post-1246-0-66999500-1382037438_thumb.jp

@experts: please check

Get the Module here: https://github.com/kixe/ProcessLanguageTranslatorPlus

or here: http://modules.processwire.com/modules/process-language-translator/

 

  • Like 6
Link to comment
Share on other sites

  • 2 weeks later...

What I'm doing wrong. I installed module and changed the process of LanguageTranslator in admin to use the TranslatorPlus, but nothing changed and still get the same language translator.

Also for me the LanguageTranslator admin page isn't locked for me. I'm using latest PW dev.

Link to comment
Share on other sites

Hmm, ok maybe I'm dumb but didn't see that only the add new translation screen has changed. :)



I get this warning:

Notice: Undefined variable: lang in /.../site/modules/ProcessLanguageTranslatorPlus/ProcessLanguageTranslatorPlus.module on line 113

Link to comment
Share on other sites

@soma
thanks for your help
in debugging. bug fixed.


Got the following Error while trying to install the module via modules manager without required installation:

Error: Class 'ProcessLanguageTranslator' not found (line 21 of /Users/c/Sites/processwire/sitet/modules/ProcessLanguageTranslatorPlus/ProcessLanguageTranslatorPlus.module)

Installation via admin > modules is impossible(disabled) without required Installations.

How can I fix this?


 

Link to comment
Share on other sites

You could install the modules required by adding another rule to info array

"installs" => "ProcessLanguageSupport"

or 

"installs" => array("ProcessLanguageSupport","AnotherOne");

That will install those modules before yours.

Or you can install them in the install routine of your module simply with a get() call

wire("modules")->get("ProcessLanguageSupport");

From the perspective of modules manager I'm not sure I can add something that would check. I'm interested what happens when you install your module using core "New" feature. You enter your modules class name and it will ask to download it if found.

Link to comment
Share on other sites

@ryan
Module requires ProcessLanguageTranslator which is part of ProcessLanguageSupport. No effect on the error. Do you recommend to change that? Why?

@Soma
tried out all options. Still get the Error without changing the following.

class ProcessLanguageTranslatorPlus extends ProcessLanguageTranslator { ...

Error occurs because the class to be extended couldn't be found. How to prevent from an Error if a downloaded module extends a non existing or not installed class? Any experiences?

Link to comment
Share on other sites

That seems a problem both ModulesManager download/install and core Modules "New" download/install suffers from.

Problem seems to be that calling getModuleInfo() inits the module and since ProcessLanguageTranslator isn't installed yet, it throws the error because the class isn't loaded.

I fixed it with a little workaround. So it will disable installing when there's requirements that aren't yet met.

I pushed an update to ModulesManager just now. Also with some little improvements to the data table.

Link to comment
Share on other sites

@ryan

Module requires ProcessLanguageTranslator which is part of ProcessLanguageSupport. No effect on the error. Do you recommend to change that? Why?

Sorry, I wasn't thinking about the fact that your module actually extends ProcessLanguageTranslator. What you'd need to do instead is include the ProcessLanguageTranslator.module file somewhere outside of your class. I would put this before the class definition. 

require(wire("config")->paths->modules . "LanguageSupport/ProcessLanguageTranslator.module"); 

You may also be able to do this (below) instead, but it would have the effect of installing the ProcessLanguageTranslator module, which you may not want or need to do in this case. 

wire("modules")->get("ProcessLanguageTranslator"); 
Link to comment
Share on other sites

I don't think he needs to do anything, but ModulesManager and Core modules manager (download/install)

I reported issue on github for this. I got it working by cycling all modules and calling their $modules->getModuleInfo(modulename); which will not install the module but init it. This is the only way I found to still be able to call getModuleInfo on the module after downloading to check for requirements and show install button or not. Because now both modules manager are missing this step and just show install button. It is no problem on the listing (table view) as there is all this happening already and checked for "requires".

Link to comment
Share on other sites

Does using require() in the module not work in this case? This is typically what any PHP class that extends another needs to do (require the class it's extending). That's of course in lieu of an autoload or something else doing it. If there's a way we can do it for them that's great, but cycling all the modules is kind of an expensive operation. I've also been thinking that I could have PW's core Modules.php parse the getModuleInfo() on it's own separately from PHP (loading it as a text file), bypassing any requirements needed by the class definition. Or just providing the option for the way PW1 did it: a separate ini or json file for the module info (i.e. MyModule.info). 

Link to comment
Share on other sites

@Soma
thanks for updating Modules Manager to 1.0.9.

@ryan
Would be nice to disable Installation Button in Admin > Modules > New, as it is already set in Admin > Modules > Site.
On the other hand, isn't it anyway better to put the requirements outside the class?

Link to comment
Share on other sites

Tested first way Ryan recommended.
Loading http://mysite/processwire/module/ is impossible after placing the requirement outside the class like:
 

require(wire("config")->paths->modules . "LanguageSupport/ProcessLanguageTranslator.module");

Got this error:
Compile Error: Cannot redeclare class ProcessLanguageTranslator (line 350 of xxx/wire/modules/LanguageSupport/ProcessLanguageTranslator.module)

Link to comment
Share on other sites

If you are getting a redeclare error, then you'd just use require_once() rather than require(). That tells PHP to include the file only if it hasn't already been included. That should accommodate either situation. 

Link to comment
Share on other sites

  • 3 months later...

How does it come that some files that are translatable are not shown in the select, and since I can't enter one manually after this module is installed I have to deinstall it.

For example wire/modules/Fieldtype/FieldtypeComments/CommentForm.php isn't in select.



EDIT: Stupid me didn't see that CommentForm.php was already added, so it doesn't show... 

Link to comment
Share on other sites

  • 6 months later...
  • 4 years later...

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

×
×
  • Create New...