Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different solution for TranslateBehavior #4509

Closed
farook-walker opened this issue Sep 6, 2014 · 15 comments
Closed

Different solution for TranslateBehavior #4509

farook-walker opened this issue Sep 6, 2014 · 15 comments
Milestone

Comments

@farook-walker
Copy link

Loading current translation for associated models should be implemented. Why i can't read translations for current locale in a straightforward way like $page->post->title. I implemented a temporary solution using query formatter, by loading all translations for associated models than extracting translation for current model and assigning translated values for required fields, but it is a tedious and clumsy one and slows the query process down. I think this feature should definitely be added into TranslateBehavior..

@lorenzo
Copy link
Member

lorenzo commented Sep 6, 2014

It is possible. You need, though, to set the table class to a specify locale

$this->Articles->locale('es_es');
$this->Articles->Comments->locale('es_es');

$this->Articles->find()->contain('Comments'); 

@lorenzo lorenzo added this to the 3.0.0 milestone Sep 6, 2014
@lorenzo lorenzo added the On hold label Sep 6, 2014
@ionas
Copy link
Contributor

ionas commented Sep 6, 2014

You could probably add AppTable.php and specify a default Translatable language there and then add $this->locale($this->defaultLanguage) to beforeFind (of AppTable and/or YourTable.php). I did not test this so I am not sure if beforeFind is run on the contains queries or if there is a more elegant way to set the locale "app wide" per default.

@ADmad
Copy link
Member

ADmad commented Sep 6, 2014

Use cases like this does make the idea of having an AppTable by default sound appealing.

@lorenzo
Copy link
Member

lorenzo commented Sep 6, 2014

TranslateBehavior is still missing a feature that I never got around to do as I was waiting after finishing the I18n stuff. It should work similar to 2.x as in automatically finding based on the current locale.

@ionas
Copy link
Contributor

ionas commented Sep 6, 2014

I'd still rather set it as per default per Table instead of some global configuration. I do like AppModel, AppEntity and AppController more than global configuration. But maybe I am alone there.

p.s.: AppTable is still possible, you just have to do it.

@robertpustulka
Copy link
Member

@ADmad @ionas but while writing plugins you can't depend on AppTable, cause it may not exist or just break your plugin.

I am 👍 for finding locale from your environment or config.

@ionas
Copy link
Contributor

ionas commented Sep 8, 2014

@robertpustulka you can depend on your plugin's AppTable only :(. Yes.

And I do think you just brought up a big reason to include AppController, AppHelper, AppTable and AppEntity into the core; at least until there is a way found to do Convention over Configuration WITHOUT having environment/config settings. Configuring apps aside Debug/Test/Dev/Live/Prod modes simply sucks IMHO.

@dereuromark
Copy link
Member

@ionas It doesn't have to be in the "core" ;) In 2.x those were also all just APP classes - and kind of required as such. That would suffice IMO.

@robertpustulka
Copy link
Member

@ionas But as plugins should be reusable, I wouldn't set default locale in my plugin :) An actual app using my plugin should take care of this.

@ionas
Copy link
Contributor

ionas commented Sep 8, 2014

Sorry @dereuromark what I meant was the APP Skeleton, not the core.

@ionas
Copy link
Contributor

ionas commented Sep 8, 2014

@robertpustulka yes you would do that in bootstrap and then import that setting in AppTable/AppEntity and overwrite when required/on case by case.

@robertpustulka
Copy link
Member

@ionas Which leads to configuration :) You're right that you could set these values depending on table/entity. But IMO locale should fallback to some automagically set default.

@ionas
Copy link
Contributor

ionas commented Sep 8, 2014

@robertpustulka I do agree that you should get the default locale from the environment and then be able to override that in bootstrap.php / app.php but writing to global configs (e.g. defaults) from model domain is somehow weird (Iike a plugin would need to do to set itself to a new correct lang)

@robertpustulka
Copy link
Member

@ionas As I understand this, TranslateBehavior (model domain) should depend on I18n, which handles this defaults stuff. There shouldn't be any SoC conflict.

@markstory
Copy link
Member

Fixed by #4662

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants