How can set different Formatter config for each languages? I'm using yii2-localeurls to language handler.
Like this for each language:
'formatter' => [
'dateFormat' => 'dd.MM.yyyy',
'decimalSeparator' => ',',
'thousandSeparator' => ' ',
'currencyCode' => 'EUR',
],
One of the solutions is to configure it in one place near the beginning of life cycle like common controller's init or module's init.
You can detect current language and based on this set all formatter attributes like
if (Yii::$app->language === 'de') {
Yii::$app->formatter->dateFormat = 'dd.MM.yyyy';
}
Related
To avoid special characters in the URL is it possible in TYPO3 v9 to define a fallback to another language e.g. english?
Before:
mydomain.org/cn/企业/
After:
mydomain.org/cn/company/
the only way to do this is to use the hook within SlugHelper.
You can add a postModifier like this in your own extension:
$GLOBALS[TCA][pages][columns][slug][config][generatorOptions][postModifiers][Vendor\Package] = My\Class::class . '->modifySlug';
You will have the following hook parameters available.
$hookParameters = [
'slug' => $slug,
'workspaceId' => $this->workspaceId,
'configuration' => $this->configuration,
'record' => $recordData,
'pid' => $pid,
'prefix' => $prefix,
'tableName' => $this->tableName,
'fieldName' => $this->fieldName,
];
Your own hook method returns a modified slug. The record should contain the information about the language.
This way you could actually write your own code or fetch the default language slug and add it there.
Can we change the style of an input in configuration page for my module, I used this tutorial for creating my module page configuration :
Adding configuration page
Making your module work with Bootstrap
as you see in the tutorial the type of the input is 'text' and I want to change it, for exemple I want to have input 'date', like the default input date of prestashop 1.6 :
i.stack.imgur.com/9OcBC.png
problem resolved !! you need just to add datepicker in class of the input :
array(
'type' =>'text',
'label' => $this->l('Date : '),
'name' => 'date',
'class' => 'datepicker fixed-width-xxl',
'required' => true )
I am working with ZF2 and trying to setup Route configuration that uses a colon separator.
For example, the web address could be www.example.com/namespace:subject and I want to send it to a specific controller, action with the two variables. I am trying to use a Regex since the colon ":" is a special character for segments. Is there a nice way to do this? Here is my route configuration:
'dataReqs' => array(
'type' => 'regex',
'options' => array(
'regex' => '/(?<namespace>[^:]+).(?<subject>[a-zA-Z0-9_-]+)',
'defaults' => array(
'controller' => 'Application\Controller\Data',
'action' => 'get',
),
'spec' => '/%namespace%:%subject%',
),
),
EDIT: I want to use the colon as the prefix:resource format is commonly used in RDF syntax (http://www.w3.org/TR/2007/PR-rdf-sparql-query-20071112/#QSynIRI). For instance, a long uri like http://dbpedia.org/data/Semantic_Web with a #prefix dbp: http://dbpedia.org/resource/ may be referred in a document with dbp:Semantic_Web. So for my Linked Data server I could direct requests and include the prefix (namespace) and the resource name; eg http://myserver.com/dbp:Semantic_Web. While I am using the segment combinations /namespace/resource for now, it would be nice to handle a route with prefix:resource syntax.
Do not use colon in your route. It isn't good practice, because colon is reserved character(see https://www.rfc-editor.org/rfc/rfc3986#section-2.2)
I'm inclined to agree with kormik. Why do you want to specify URL's in that way? What is wrong with the default behavior?
www.example.com/namespace/subject
eg:
www.example.com/somenamespace/10
or even:
www.exmple.com/namespace/namespace/subject/subject
eg
www.example.com/namespace/somenamespace/subject/10
you can easily grab these parameters in the controller like so:
$ns = $this->params()->fromRoute('namespace',0);
$subject = (int) $this->params->fromRoute('subject',0);
You would need to modify the route config also.
I'm writing a new version of an API and would like to support legacy versions by having distinct sets of controllers for each version. Within the default "app\controllers" path in Lithium, I would like to have for example "v1" and "v2" paths.
I have tried accomplishing this within the route itself by doing something like:
Router::connect('/{:version}/{:controller}/{:action}{:args}', array(
'controller'=> '\app\controllers\{:version}\{:controller}Controller',
), array());
Then I tried overriding the path in the libraries bootstrap module by doing something like:
if( preg_match('/^\/(v[0-9\.]+)/', $_SERVER['REQUEST_URI'], $match) ) {
Libraries::paths(array(
'controllers' => "controllers\\".$match[1].'\\{:name}Controller',
'models' => "models\\".$match[1]."\\{:name}",
));
}
I spent about a half a day at work searching google and the very sparse lithium docs. I am not sure what release of Lithium we are using as I have stepped into this pre-existing code base.
Thanks for any tips you may have!
In your routes.php file, you should re-configure the Dispatcher default rules with
Dispatcher::config(array('rules' => array(
'v1' => array('controller' => 'app\controllers\v1\{:controller}Controller')
)));
and a continuation route to match /v1/... requests
Router::connect('/v1/{:args}', array('v1' => true), array(
'continue' => true, 'persist' => array('controller', 'v1')
));
You can easily use :version instead of a predefined version number if you need so.
I want to convert my XML document to Hash in Ruby/Rails. Actually, the default conversion by Hash.from_xml in Rails works for me except in one case.
I have a list of items contained in <item-list> element, these items can be of different types though. For instance, standard-item and special-item, each of which has different set of child elements.
<item-list>
<standard-item>
<foo>...</foo>
<bar>...</bar>
</standard-item>
<standard-item>
<foo>...</foo>
<bar>...</bar>
</special-item>
<special-item>
<baz>...</baz>
</special-item>
</item-list>
This XML structure can be confusing for Hash.from_xml as it does not know that both standard-item and special-item are both items and should be in the same level. Hence, from the above XML, the hash generated by Hash.from_xml will be:
{ 'item-list' => { 'standard-item' => [ { 'foo' => '...', 'bar' => '...' },
{ 'foo' => '...', 'bar' => '...' } ],
'special-item' => { 'baz' => '...' } }}
But what I want is to have all items as list members, like this:
{ 'item-list' => [ { 'standard-item' => { 'foo' => '...', 'bar' => '...' } },
{ 'standard-item' => { 'foo' => '...', 'bar' => '...' } },
{ 'special-item' => { 'baz' => '...' } } ]
Is it possible to extend/customize from_xml so that it performs to way I want to for this case? If it is not possible, what is the best way to achieve this? Given that this is the only element that contains something that deviates from general XML-to-Hash conversion, it does not seem right to me to implement the whole conversion routine where it might have already been implemented for a thousand times.
Another small note, Hash.to_xml also replaces all dashes with underscores. Is there a way to prevent this replacement?
This is correct behavior.
<a>
<b>one</b>
<b>two</b>
</a>
Think about how this would be converting to a hash, there cannot be two values assigned to the key 'b'. The only solution is to make the value of 'b' a hash containing an array of 'one' and 'two'.
{a => {
b => ['one', 'two']
}}
This is simply how Rails represents XMLs. You will need to check for an array value in the hash, and act accordingly.