Laravel mcamara/laravel-localization package overrides config('app.locale') - laravel

I'm trying "mcamara/laravel-localization" package to localize my app and it works as expected except for one small issue, the package seems to override the config('app.locale') default value.
For instance if the default value of the locale property in config\app.php file is set to en end I changed the application language to french with the language switcher then config('app.locale') is evaluated to fr instead of the default en.
I hope the issue is clear so my question is: how can get the default locale as defined the config\app.php config file?
Thanks

whole point of that package is changing locale, no matter what the default locale is that package change it to whatever you config it to.
but you can get current locale anytime you want using currentLocale() method of App facade and change it with setLocale($yourLocale).

In order to get the current language code, write the following function:
app()->getLocale();
In order to activate the activation of a new language, you can write the following function:
app()->setLocale('fr');

Related

Silverstripe 4.6 setup .env - vars, missing install.php, language?

In the docs, they say, the install.php no longer exists within SS 4.6.x.
So you have to setup with .env - variables
my .env looks like this:
SS_BASE_URL="http://localhost/SS_4_6_1"
SS_DATABASE_CLASS="MySQLPDODatabase"
SS_DATABASE_NAME="ss_4_6_1"
SS_DATABASE_PASSWORD="root"
SS_DATABASE_SERVER="localhost"
SS_DATABASE_USERNAME="root"
SS_ENVIRONMENT_TYPE="dev"
SS_DEFAULT_ADMIN_USERNAME="XXX"
SS_DEFAULT_ADMIN_PASSWORD="XXX"
Doing a .../dev/build...
Database is created.
I know i can change Cms-language to German for the Default- admin in the CMS.
BUT all pages created while setup are in English. (inclusive Error - Pages) ??
CAN YOU CHANGE THE DEFAULT - LANGUAGE TO e.g. GERMAN FOR SETTING UP THE SITE?
EDIT: It would be nice, to set language in .env:
SS_DEFAULT_LOCALE="de_DE"
Yes, we can change the default language for setting up the site.
Before we run the initial dev/build we can add the following to our app config.yml:
SilverStripe\i18n\i18n:
default_locale: 'de'
When dev/build runs it will populate the default pages with the specified language.

freemarker - access settings variable in template

Is it possible to access a settings variable within a template?
Setting:
<#setting locale="${bean.locale}">
How can I use locale without reusing ${bean.locale} within the template to avoid duplicate code, especially if its a deeper hierarchy?
The locale is a Special Variable, and can be access like this : ${.locale}.
See the freemarker documentation

How to customize validation messages in Laravel?

I searched a lot before asking this question but found nothing to help me.
I started using Laravel as a PHP framework. As I started to do form validation, I used the Validator class to manage all my validation and error messages. But I'd like to know how I can customize the error messages (I'd like to put them in another language for example).
The documentation says:
Language strings are stored in files within the resources/lang directory. Within this directory there should be a subdirectory for each language supported by the application.
Just create a directory with the supported language code, and add a validation.php file (it is wise to just copy the one provided in English then start translating).
An example for Spanish translation would be created at resources/lang/es/validation.php. And it will look as follow:
<?php
return array(
"required" => "El campo :attribute es requerido.",
);
After that, you will need to change the default language.
The default language for your application is stored in the app/config/app.php configuration file. You may change the active language at any time using the App::setLocale method.
Example of changing the default language at runtime:
App::setLocale('es');
in laravel 5 the validation.php file comes under the folder resources.
resources/lang/en/validation.php

Add new variable to magento core config

What is the best way to add a new config setting in the configuration->Catalog->Search Engine Optimisations or any other such location in the core configuration.
I am developing an extension which will need to use this setting that I will define here.
Thanks
karam
If you are developing an extension, you can configure your field for administration using system.xml. The xpath will be catalog/groups/seo/fields/your_field (ref. Mage/Catalog/etc/system.xml).
To set a default for this value, you can either add the value to your module's config.xml using the xpath default/catalog/seo/your_field, or you can create an install script which will write the value to core_config_data.

Translator using container locale parameter instead of the session locale

I have defined my routing using the special _locale parameter. When a route is matched by the router, the locale is correctly set in my user session and I can see the correct locale being used in the profiler.
$this->get('session')->getLocale(); // Return the correct locale
The problem is that the i18n translator is always using the default locale defined in my parameters.yml file instead of using the locale set in the session.
Is there something i'm missing ? Do I have to manually pass the session locale to the translator ?
I'm using Symfony 2.0.9.
According to this link: Translations configuration, "The locale used in translations is the one stored in the user session.". If it's not the case for you, I guess you changed something in your configuration?
By the way, the locale will be stored in the request and not in the session anymore in 2.1: https://github.com/symfony/symfony/commit/74bc699b270122b70b1de6ece47c726f5df8bd41

Resources