cakePHP 3.3 internationalization - cakephp

How can I set multiple language in case text is in array?
I know that if I use this
<?= __('username')?>
and in directory /src/Locale/de_DE/default.po
I have written following
msgid "username"
msgstr "benutzer"
It's gonna change username to benutzer if I set language to de_DE (german)
But what to do if I have this
<?= $this->Form->input('password',['label' =>'Password']); ?>
and I would like to change label Password

Simple:
$this->Form->input('password', ['label' => __('Password')]);
The __() function simply returns the translated string (more info). In your example you used
<?= ... ?>
which is equivalent to
<?php echo ... ?>

Related

Cakephp echo username into page title

I am currently learning Cakephp and have made a profile page of which displays the username on it. You can only access this page when logged in so when you are on this page, I wish to display the username of the user in the HTML page title. This is also because your profile page is visible to other users.
At the moment to get the page headers I have used.
<title><?php echo $this->fetch('title'); ?> | Site Name</title>
<? $this->assign('title', 'Profile')?>
And to display the username on the page currently I have:
<?php echo $user['User']['user_name']; ?>
I have attempted to combine these two into something like shown below but clearly that's not working. Any ideas?
<? $this->assign('title', '<?php echo $user['User']['user_name']; ?>')?>
Thanks!
Mistake in the concatenation, change this in your .ctp
<? $this->assign('title', '<?php echo $user['User']['user_name']; ?>')?>
to this
<? $this->assign('title', $user['User']['user_name'])?>
Later on add this in your layout
<title><?php echo $this->fetch('title'); ?> | Site Name</title>
This will work :)

Meta noindex in post and page untranslated (unavailable) with Yoast

Is possible enter in the of posts and pages untranslated a meta robots noindex?
Of course, versions already translated, must instead stay indexable ...
I have Yoast SEO plugin compatible but I can not change meta robots per single language.
Just put this in the header of your theme. Language plugin that I use is qtranslate:
<!--Begin add noindex and nofolllow when not translated post in current lang-->
<?php if ( have_posts() && is_single() ) : while ( have_posts() ) : the_post();
$lang_current =qtranxf_getLanguage();
$id = get_the_id();
$exist_translate = qtranxf_isAvailableIn($id, $lang_current);
if (! ($exist_translate) ) : ?>
<meta name=“robots” content=“noindex,nofollow”>
<?php endif;?>
<?php endwhile;?>
<?php endif; ?>
<!--End add noindex and nofolllow when not translate post in current language-->

Internationalization - how to handle gender?

I have a cakephp 3 application I'm currently internationalizing. The app is written in french, I'm adding english.
I'm using the built in tools of cakephp 3 to do it. There is a sentence in my app that must be translated differently in english whether the user is a man or a woman. In french, the sentence remains the same.
French sentence: "xxx n'a pas indiqué ses disponibilités"
English translation: "xxx did not give his availabilities" for a man, "xxx give her availabilities" for a woman.
At first, my app looked like this:
<?= __("{0} n'a pas indiqué ses disponibilités", $user->name); ?>
I changed it so that two different translations could be provided:
<?php if ($user->gender == 'M'): ?>
<?= __("{0} n'a pas indiqué ses disponibilités", $user->name); ?>
<?php else: ?>
<?= __("{0} n'a pas indiqué ses disponibilités", $user->name); ?>
<?php endif; ?>
But when generating the pot file with bin/cake i18n extract only one sentence was extracted. I've then tried this:
<?php if ($user->gender == 'M'): ?>
<?= __x("speaking of a man", "{0} n'a pas indiqué ses disponibilités", $user->name); ?>
<?php else: ?>
<?= __x("speaking of a woman", "{0} n'a pas indiqué ses disponibilités", $user->name); ?>
<?php endif; ?>
Still, only one msgid is recorded in the pot file. How to handle this kind of issue?
Using the context translation function is the way to go, your last example is the correct way of handling such cases.
The problem is the I18N shells extract task, it uses only the message as the identifier to store the extracted values, resulting in the previous contexts to be overwritten. I would consider this to be a bug, please report it over at GitHub.
Until this is fixed you'll have to manually add the missing messages to your .pot file.

How to add two calendars in a page - Joomla

I am new to joomla, want to implement two calendars in a page ...
From :
<?php
echo JHTML::calendar('sch_from', 'sch_from', '%Y-%m-%d');
?>
To :
<?php
echo JHTML::calendar('sch_to', 'sch_to', '%Y-%m-%d');
?>
But first calendar only working... is there any issue in code?
syntax is:
JHtml::calendar($value,'nameOfField','idOfField', '%Y-%m-%d');
located at libraries/cms/html/html.php
try
From :
<?php
echo JHTML::calendar('','sch_from', 'sch_from', '%Y-%m-%d');
?>
To :
<?php
echo JHTML::calendar('','sch_to', 'sch_to', '%Y-%m-%d');
?>

My view in cakephp give error "Call to a member function create() on a non-object ",why?

View contain following code:-
<?php
echo $form->create('Post',array('action'=>'add'));
echo $form->input('title');
echo $form->input('body');
echo $form->end("Create a post");
?>
As mentioned in the official documentation it is not
$form
but
$this->Form
And that since CakePHP1.3

Resources