JText placeholder does not produce correct code #606

Closed
opened 2020-10-09 08:19:35 +00:00 by infotecnica · 6 comments
infotecnica commented 2020-10-09 08:19:35 +00:00 (Migrated from github.com)

Steps to reproduce the issue

This code in the site view default tmpl:

<th class=''><?php echo JText::_('Dayweek'); ?></th>
<th class=''><?php echo JText::_('Classroom'); ?></th>

Expected result

<th class=''><?php echo JText::_('COM_CLASSROOM_TIMETABLE_DAYWEEK'); ?></th>
<th class=''><?php echo JText::_('COM_CLASSROOM_TIMETABLE_CLASSROOM'); ?></th>

Actual result

<th class=''><?php echo JText::_('Dayweek'); ?></th>
<th class=''><?php echo JText::_('Classroom'); ?></th>

System information (as much as possible)

  • OS Name & Version: Linux vmi309661
  • MySql Version: 5.5.65-MariaDB
  • Apache Version: 2.4.6-93.el7.centos
  • PHP Version: 7.4.11
  • Joomla Version: Joomla! 3.9.22
  • JCB Version: 2.11.4
  • Browser: Firefox Browser 81.0.1 (64 bit)

Additional comments

This situation does not allow me to be able to translate with jcb but only to do it manually

### Steps to reproduce the issue This code in the site view default tmpl: ``` <th class=''><?php echo JText::_('Dayweek'); ?></th> <th class=''><?php echo JText::_('Classroom'); ?></th> ``` ### Expected result ``` <th class=''><?php echo JText::_('COM_CLASSROOM_TIMETABLE_DAYWEEK'); ?></th> <th class=''><?php echo JText::_('COM_CLASSROOM_TIMETABLE_CLASSROOM'); ?></th> ``` ### Actual result ``` <th class=''><?php echo JText::_('Dayweek'); ?></th> <th class=''><?php echo JText::_('Classroom'); ?></th> ``` ### System information (as much as possible) - OS Name & Version: Linux vmi309661 - MySql Version: 5.5.65-MariaDB - Apache Version: 2.4.6-93.el7.centos - PHP Version: 7.4.11 - Joomla Version: Joomla! 3.9.22 - JCB Version: 2.11.4 - Browser: Firefox Browser 81.0.1 (64 bit) ### Additional comments This situation does not allow me to be able to translate with jcb but only to do it manually

Okay on the forum you had the text in all caps, now you don't. Is this by mistake? Since we do not know of this error, I in fact have hundreds of site views which translate just perfectly.

Okay on the [forum you had the text in all caps](https://groups.google.com/a/vdm.io/forum/?oldui=1#!topic/jcb/ZcKfpGgK5lU), now you don't. Is this by mistake? Since we do not know of this error, I in fact have hundreds of site views which translate just perfectly.

Like this one:
image
Then in the code:
image

Like this one: ![image](https://user-images.githubusercontent.com/5607939/95585775-fe43b680-0a3f-11eb-8597-c5889efe1fc0.png) Then in the code: ![image](https://user-images.githubusercontent.com/5607939/95586245-b5403200-0a40-11eb-85cb-d8aa13e4750d.png)
infotecnica commented 2020-10-09 14:15:23 +00:00 (Migrated from github.com)

I apologize for the misunderstanding but I tried both ways with all caps and lowercase but always with the same result.
However, I noticed that in other applications I did not have this error and I would not want it to be a wrong setting somewhere because then suddenly it didn't work anymore

I apologize for the misunderstanding but I tried both ways with all caps and lowercase but always with the same result. However, I noticed that in other applications I did not have this error and I would not want it to be a wrong setting somewhere because then suddenly it didn't work anymore
infotecnica commented 2020-10-09 16:12:36 +00:00 (Migrated from github.com)

I found out what was not doing the translations.
This code to get the current day of the week:

<?php $dateTime = new \DateTime('now', new \DateTimeZone('Europe/Rome'));
$gw = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday', 'Saturday' );
$D = $gw[date('w')] ;?>
<h1>Calendario Lezioni del giorno: <?php echo JText::_('' .$D) ;?> <?php echo (date("d/m/Y")); ?></h1>

This before JText Thead
replacing <? php echo JText :: _ (''. $ D);?> with <? php echo JText :: _ ($ D);?> works.

It's weird because the same code put after the JText Thead doesn't cause errors

I found out what was not doing the translations. This code to get the current day of the week: ``` <?php $dateTime = new \DateTime('now', new \DateTimeZone('Europe/Rome')); $gw = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday', 'Saturday' ); $D = $gw[date('w')] ;?> <h1>Calendario Lezioni del giorno: <?php echo JText::_('' .$D) ;?> <?php echo (date("d/m/Y")); ?></h1> ``` This before JText Thead replacing `<? php echo JText :: _ (''. $ D);?>` with `<? php echo JText :: _ ($ D);?>` works. It's weird because the same code put after the JText Thead doesn't cause errors

The way you are trying to make this work is making no sense at all. Instead do something like this:

<?php $datenow = new Joomla\CMS\Date\Date(); ?>
<h1>
	Calendario Lezioni del giorno:
	<?php echo $datenow->dayToString($datenow->dayofweek); ?>
	<?php echo $datenow->format("d/m/Y"); ?>
</h1>

This manages the time zone, and translation. Should you like to set the time zone manually, then you could do something like this:

<?php $datenow = new Joomla\CMS\Date\Date('now', new \DateTimeZone('Europe/Rome')); ?>

Hope this will resolve the issue for you, just in-case you want to in the future use an array again as a translated set of strings, you should rather do it like this:

// in JCB - GUI
$day = 3; // dynamic day
$lang_days = array(
	JustTEXT::_('Sunday'),
	JustTEXT::_('Monday'),
	JustTEXT::_('Tuesday'),
	JustTEXT::_('Wednesday'),
	JustTEXT::_('Thursday'),
	JustTEXT::_('Friday'),
	JustTEXT::_('Saturday')
);
echo JText::_($lang_days[$day]);

The result code will look like this:

// resulting code
$day = 3; // dynamic day
$lang_days = array(
	'COM_COMPONENT_SUNDAY',
	'COM_COMPONENT_MONDAY',
	'COM_COMPONENT_TUESDAY',
	'COM_COMPONENT_WEDNESDAY',
	'COM_COMPONENT_THURSDAY',
	'COM_COMPONENT_FRIDAY',
	'COM_COMPONENT_SATURDAY'
);
echo JText::_($lang_days[$day]);

But with the date, it is really not needed.

The way you are trying to make this work is making no sense at all. Instead do something like this: ```php <?php $datenow = new Joomla\CMS\Date\Date(); ?> <h1> Calendario Lezioni del giorno: <?php echo $datenow->dayToString($datenow->dayofweek); ?> <?php echo $datenow->format("d/m/Y"); ?> </h1> ``` This manages the time zone, and translation. Should you like to set the time zone manually, then you could do something like this: ```php <?php $datenow = new Joomla\CMS\Date\Date('now', new \DateTimeZone('Europe/Rome')); ?> ``` Hope this will resolve the issue for you, just in-case you want to in the future use an array again as a translated set of strings, you should rather do it like this: ```php // in JCB - GUI $day = 3; // dynamic day $lang_days = array( JustTEXT::_('Sunday'), JustTEXT::_('Monday'), JustTEXT::_('Tuesday'), JustTEXT::_('Wednesday'), JustTEXT::_('Thursday'), JustTEXT::_('Friday'), JustTEXT::_('Saturday') ); echo JText::_($lang_days[$day]); ``` The result code will look like this: ```php // resulting code $day = 3; // dynamic day $lang_days = array( 'COM_COMPONENT_SUNDAY', 'COM_COMPONENT_MONDAY', 'COM_COMPONENT_TUESDAY', 'COM_COMPONENT_WEDNESDAY', 'COM_COMPONENT_THURSDAY', 'COM_COMPONENT_FRIDAY', 'COM_COMPONENT_SATURDAY' ); echo JText::_($lang_days[$day]); ``` But with the date, it is really not needed.
infotecnica commented 2020-10-10 06:54:03 +00:00 (Migrated from github.com)

Thank you for the full explanation and will do as recommended

Thank you for the full explanation and will do as recommended
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: joomla/Component-Builder#606
No description provided.