Cakephp with Translate Behavior - cakephp

I have setted the translate behavior and it work fine, but I need something more.
If I haven't translated the fields, I need that the find() return me fields in default languge (this case eng).
How I could do it?

By default, if cake cannot find the language translations for the given language, it will default to what is set in the application. So this should already be working. Confirm that you have all of the english translations filled out. If this is still not working, you will need to provide some code and examples of what is not working.

Related

reactjs i18n change translation on demand

I use i18n (react-i18next) in my react js application. Translation with language chooser etc works absolutly fine.
But now I want to change some texts programmatically on demand.
I tried this:
i18n.t('clinical:sde.export.studyTitle', {lng: "en"})
and
i18n.t('clinical:sde.export.studyTitle', {"en"})
It always returns the german string from current setting and not the "on demand" english text. Is there a solution to solve this?
Thanks in advance.
Your code should work, you need to check that the dynamic language is loaded (this what i18n.changeLanguage does).
I've made a simple test, and it works.
https://codesandbox.io/s/react-i18next-example-forked-ueng1?file=/src/app.js

angular translate, how to get all the translate of one specific word in controller

I know that in controller I can use $translate.instant('HELLO_WORLD'), to get the translate to the 'current' set language.
What if the current is french, and I want to get english of 'HELLO_WORLD' too, but not changing the user's current preferred language.
The reason I want this is casue my app let user switch between french and english at any time. Everything works except for a directive that uses a $rootScope.object, the words inside doesnt get updated when user change the language.
The way Im trying to do it by is, I use a listener on this rootScope.object, when it get change, I manually change the item inside. However I need to know both french and english translate of each word to make the comparison and change.
The $translate.instant() API has a force language parameter. If you know your supported languages ahead of time you could query them all using separate calls to .instant().
instant(translationId, interpolateParams, interpolationId, forceLanguage, sanitizeStrategy)

cakephp how to check variable content and all function included?

sorry i was new here so this problem maybe simple.
anyone knows how to check variable content?
like xx($a);
then page shows all relate information about $a. Is CakePHP allowed to do that?
i setup a kit on my cakephp
You might be looking for either var_dump() or print_r()
You can use PHP built-in functions like
var_dump() - displays structured information about variable
print_r() - the same, but preformatted with some differences
get_defined_vars() - returns array with all defined variables
Or use true CakePHP-way
Debugger::dump() - It will print out all properties and methods (if any) of the supplied variable
For more convenience you may use CakePHP Debug Kit plugin, which provides nice toolbar and some useful tools for your purpose.

How to add a custom field into template.php using Zen sub theme

First time poster here, I'm a designer not skilled at all with php and I have a small issue I don't seem to be able to solve. I'm making a site in drupal 7 using a sub theme on zen.
Btw this is a great CMS, even though people say it's really more a developers CMS. I have no trouble to do what I need using views, rules, display suite etc. So a big thank you for all the developers out there making this such a good CMS. But for this apparently simple problem... no module will help me (I think) and I'm kinda stuck.
So here it is: I'd like to add a subtitle next to the title in all my pages.
So what I did was to add a custom field into the content type basic page (machine name: field_sub_title) which is a simple text field.
I uncommented the following line in my template.php
function mytheme_preprocess_page(&$variables, $hook) {
$variables['sub_title'] = t('field_sub_title');
}
Now my question is how do I load the content of my custom field into that variable?
I know i need to change the second part, but I don't have a clue as into what I need to change this.
Displaying the variable into the the page.tpl.php is something I know about so I only need help with the first part.
{EDIT}
Ok I found how to do this :)
I was looking for a solution in the wrong place. I don't need to change any thing in the template.php file.
Just needed to add this bit of code into my page.tpl.php:
<?php
print $node->field_sub_title['und'][0]['value'];
?>
So I'm posting this here for other Drupal newbies struggling with this....
Your solution may work for now, but there may be a more Drupal-y way to handle a problem like this. If you haven't noticed any problems yet, you may find one or more of the following issues down the road:
Someone who doesn't know php or Drupal theming may need to change the way this works.
If you're like me, you may forget where exactly in code this was implemented.
You may see superfluous markup and/or errors on nodes (content) that do not have this sub-title field (ie. event content not having a sub-title field while basic pages and news articles do).
When you add a field to a content type, it will automatically appear anytime content in that content type is displayed. You should be able to add the sub-title field for your page, event or whatever else you need and have it automatically appear in the markup.
You can 'manage display' of a content type to drag and drop the order for fields to appear. You could take it a step further by using a module like Display Suite to add formatting or layout per-content type.
If you feel like this isn't good enough and the markup for the subtitle must be at the same level as the page title (which is rare), at least add an if statement to make your code check to see if the variable is present before trying to print it. I'd also add a new variable and comments for code readability.
<?php
$subtitle = $node->field_sub_title['und'][0]['value'];
if($subtitle){
print $subtitle;
}
?>
Consider using field_get_items or field_view_value, or at least use the LANGUAGE_NONE constant instead of 'und'
See https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_get_items/7 and https://api.drupal.org/api/drupal/modules!field!field.module/function/field_view_value/7
This has the added benefit of reducing the number of potential security holes you create.

CakePHP: I can't understand this in translate behavior

in cakebook on page http://book.cakephp.org/view/1331/Defining-the-Fields there is a sentence what I am not able interpret:
When defining fields for TranslateBehavior to translate, be sure to omit those fields from the translated model's schema. If you leave the fields in, there can be issues when retrieving data with fallback locales.
Can somebody explain me in a more simple way than it is in originally?
I think I have language problem as english is not my native :P
It means that in the following case:
class Article extends AppModel
{
var $actsAs = array('Translate' => array('title'));
}
You should not have the field Article.title (i.e. articles.title) in your database, otherwise you'll have trouble at some point.
Basically, when you design your table you plan to translate, omit those fields you want to translate.
Hope that helps!
I've never used that behaviour and I have to say that I would be looking elsewhere for an explanation of how to use it as I too (and I'm English) am having trouble understanding it.
My guess is that you need to ensure that there are no fields in the i18n table with the same name as a field that you are translating, i.e. if you are translating Post.name you must be careful not to have i18nTable.name
I don't use the console and there is no explanation of the required name or structure of the i18n table, so my comment is guesswork but I hope that it is in someway helpful.

Resources