Zend locale number format - zend-framework

I would like to set up number decimal delimiter based on selected locale, and while I can do this:
Zend_Locale_Format::toNumber($number, array('locale' => $locale, 'precision' => 2));
It doesn't quite work 'globally'. Is there a way to say to format all numbers across the app to conform to selected locale?
Zend version is 1.12

You can set the default Locale at Bootstrap.php
Zend_Locale::setDefault('pt_BR');
But it will not work for the precision option

Related

Thousand separator in symfony input form

I have in my symfony5 form input
->add('required_amount', IntegerType::class, [
'label' => 'Požadovaná částka',
'grouping' => true,
]);
when run form the thousand sepator isn dispaly on typing number
whatis wrong in my code, may I use number format in input in form in symfony
I copy your code and runs just fine to my 4.4.4 symfony project. If you submit this form the output will be 1,000,000 or 1.000.000 depending on your locale value default set in .env file. The grouping property is in IntegerType , MoneyType and NumberType and do the same in all this classes , so this is not your problem. If you describe something in client side (as you type the numbers to add the separator) you need to go with javascript not php, but i don't thinks this is the case.

CakePHP 3.6 multi language form

As mentioned in CakePHP 3.6.10 Translate behaviour not showing 'defaultLocale' values the default language values should be saved in the source table so they can be used as a fallback for empty fields in other languages.
However I have a problem building the forms for this. I have 5 languages (locales): en_US, nl_BE, fr_BE, de_BE and ru_RU. The defaultLocale is en_US. So to ADD a new record I did:
// for the defaultLocale
echo $this->Form->control('title');
// for all other languages I iterate over every language except of the defaultLocale
foreach ($supported_locales as $key => $val):
if ($key !== $default_locale):
echo $this->Form->control('_translations.' . $key . '.title');
endif;
endforeach;
This works fine. Allthough I'm not sure if this is the proper Cake-way to do it?
But in the VIEW (using a disabled form) and EDIT the defaultLocale field
echo $this->Form->control('title');
shows the translated value of the selected locale at that moment instead of the defaultLocale which is saved in the source table. F.e. when you switched the language to Russian at that moment you'll get to see:
English: Русский титул
Dutch: Nederlandse titel
French: Titre français
Deutsch: Deutscher Titel
Russian: Русский титул
So you're missing the value for the default locale (English) because it's replaced by the value for the currently selected language (here Russian). And you're not able to edit the value for the default locale when you're using the page in another language.
Am I overlooking something and is there a easier way to make this work 'out of the box'?
You must make sure that you fetch the records in the default locale, irrespectively of the current environments locale. You can do so using the translate behaviors setLocale() method (locale() before CakePHP 3.6), to explicitly set the locale to use for a specific repository, for example:
$locale = \Cake\Core\Configure::read('App.defaultLocale');
$this->Articles->setLocale($locale);
$query = $this->Articles->find('translations');
This will retrieve the articles in the configured default locale, irrespectively of what might have been set via I18n::setLocale(). If you are including associations where you need the locale applied too, then you have to explicitly set the locale for them too, ie:
$this->Articles->setLocale($locale);
$this->Articles->Comments->setLocale($locale);
$query = $this->Articles->find('translations')->contain('Comments');
See also
Cookbook > ORM > Behaviors > Translate > Retrieving one language without using I18n::locale

CakePHP 3 change locale input date

I have the following input date on form:
echo $this->Form->input('fecha_limite', ['label' => __('Fecha límite'), 'type' => 'date', 'class' => 'form-control']);
By default the months are shown on english locale and I want to establish spanish locale.
I have tried to change it using intl.default_locale since config/bootstrap.php and using I18n::locale() and doesn't works...
Any ideas?
this problem probably has some Reason.cakephp 3 has cache for i18n therefore you must delete cache .maybe you was a mistake in file locale.you have to don't use of two line in that file.
However maybe because of use form helper.please test outside form helper

ZendFramework 2: Locale Currency values in a form

Is there any way to convert how a text input displays a currency in its value in correct locale number format from within the Form construct method or ViewHelper?
e.g.
value from database is 10000.50
In US or UK, is viewed as 10,000.50
In EUR is viewed as 10.000,50
I have been able to do the conversions in controllers, models and views, but haven't come across how do do it here.
Thanks
Aborgrove
You have the Zend\I18n component which ships formatters to format numbers. You can both use the NumberFormat for numbers in general and the CurrencyFormat for specifically currencies.
These formatters are living in the Zend\I18n\View\Helper domain, but are not dependant on the view actually. Therefore, you can just use them anywhere you want:
use Zend\I18n\View\Helper\CurrencyFormat;
$formatter = new CurrencyFormat;
$formatter->setLocale('en-US');
$currency = $formatter(1234.56, 'EUR'); // "€1,234.56"
$currency = $formatter(1234.56, 'USD'); // "$1,234.56"
$formatter->setLocale('nl-NL');
$currency = $formatter(1234.56, 'EUR'); // "€ 1.234,56"
You have to be aware of two things:
The number formatting style is depending on the locale, so supply the correct locale (or set the default locale with Locale::setDefault()).
The "EUR" or "USD" is only for the signs, and together with the locale will be prepended or appended to the number formatted
You can simply use the Zend\I18n\View\Helper\NumberFormat if you only want to format the numbers without any currency code. More information about the formatting is available in the manual.

Symfony change value of days in form

I have a problem with the form in symfony.
I have English names of the days but I would like them to be in Polish. I changed the range of the years, but the names of the days I can't
-> add ('DateOfBirth', 'date', array (
'years' => range (date ('Y') - 100, date ('Y'))
))
Any clue?
You can pass option format to change the date format itself. In this way you can make that months would be integer numbers, not full names.
When formatting, the DateType takes locale as the default: \Locale::getDefault(). So you just need to change the default locale. It is set in the parameters.ini/parameters.yml file or set via the routing or in other ways if you support multiple languages.
I suggest to look for more details in the implementation class:
https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/Core/Type/DateType.php