Translate url rules in Yii2 - internationalization

I'm trying to translate my site into different languages, thanks to Yii::t() I have translated all texts. But I'm using pretty urls and it should translate them for better user experience.
I'm using the component. translate-manager by lajax to make translations
I have tried to add Yii::t() keys of the rules, I can translate them, but when you change language ignores translation and Yii use the original rule.
This is my urlManager:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
['pattern' => '<id:rss>', 'route' => 'rss/default/index', 'suffix' => '.xml'],
['pattern' => '<id:rss>', 'route' => 'rss/default/index'],
['pattern' => 'sitemap', 'route' => 'sitemap', 'suffix' => '.xml'],
'/' => 'site/index',
Yii::t('config main', '<site:(about|contact|login|logout|signup|policy|conditions|blog)>') => 'site/<site>',
Yii::t('config main', '<device:\w+>/compare-price') => 'items/compareprices',
Yii::t('config main', 'versus/<brand1:\w+>-<model1:[\w\-]+>-<brand2:\w+>-<model2:[\w\-]+>') => 'items/versus',
Yii::t('config main', 'versus/<brand1:\w+>-<model1:[\w\-]+>-<brand2:\w+>-<model2:[\w\-]+>-<brand3:\w+>-<model3:[\w\-]+>') => 'items/versus',
Yii::t('config main', 'versus/<brand1:\w+>-<model1:[\w\-]+>-<brand2:\w+>-<model2:[\w\-]+>-<brand3:\w+>-<model3:[\w\-]+>-<brand4:\w+>-<model4:[\w\-]+>') => 'items/versus',
Yii::t('config main', '<device: \w+>/advanced-search') => 'items/advancedsearch',
],
],
Exemple:
domain.com/conditions will be domain.com/condiciones in spanish
How do I have to implement internationalization in the urls?

First of all it's not a good decision, but i'm using this approach at the moment, while i'm trying to figure out exactly the same problem:
I'm using the component codemix/yii2-localeurls for language management & language code inserted in URL.
'urlManager' => [
'class' => 'codemix\localeurls\UrlManager',
'languages' => ['ru', 'en'],
'showScriptName' => false,
'enablePrettyUrl' => true,
'enableLanguageDetection' => true,
'rules' => array(
'отдых-в-греции-цены|vacation-in-greece-prices' => 'site/prices',
),
],
I have 'отдых-в-греции-цены' in translations and my link in site is like:
<?= Html::a(Yii::t('app', 'Цены'), ['/'.Yii::t('app', 'отдых-в-греции-цены')]) ?>
As i said it's not a best practice but at the moment a can't find a better approach. Also the site is very small and i don't need complex routes like yours, but i think that it can be implemented.
Regards

Related

How to add the alt and title fields in an image field of a custom entity in drupal 8

I created a custom entity with an image field. But I can not display the alt and title fields.
Here is my code:
$fields['main_img'] = BaseFieldDefinition::create('image')
->setLabel(t('Main image of the hardware'))
->setSettings([
'file_directory' => 'hardware',
'file_extensions' => 'png jpg jpeg',
])
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'image',
'weight' => -30,
))
->setDisplayOptions('form', array(
'label' => 'above',
'type' => 'image_image',
'weight' => -30,
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
Could you tell me how to display the alt and title fields of my image and maybe someone knows where the documentation is for doing that because I can not find it?
Thank you all
I loaded one of my node field definitions with $node->getFieldDefinitions():
I believe you can try something like this:
->setDisplayOptions('form', array(
'label' => 'above',
'type' => 'image_image',
'weight' => -30,
'settings' => [
'alt_field' => TRUE,
'alt_field_required' => TRUE, //optional
'title_field' => TRUE,
'title_field_required' => TRUE, //optional
],
))
Thank Dmytro.
I feel a little stupid but it's life.
It was enough to add 'alt_field_required' => FALSE and 'title_field' => TRUE in setSettings.
But as title and alt is displayed that when we download an image I thought it did not work.
A day of lost!

Choose Amazon S3 storage class using Laravel Filesystem

Amazon S3 has different storage classes, with different price brackets.
I was wondering if there's a way I can choose a storage class in Laravel's Filesystem / Cloud Storage solution?
It would be good to choose a class on a per upload basis so I can choose throughout my application, not just once in a configuration file.
To pass additional options to flysystem you have to use getDriver()
Storage::disk('s3')->getDriver()->put(
'sample.txt',
'This is a demo',
[
'StorageClass' => 'REDUCED_REDUNDANCY'
]
);
This can be used in Laravel 7
Storage::disk('s3')->put(
'file path',
$request->file('file'),
[
'StorageClass' => 'STANDARD|REDUCED_REDUNDANCY|STANDARD_IA|ONEZONE_IA|INTELLIGENT_TIERING|GLACIER|DEEP_ARCHIVE',
]
);
You can use putFileAs() Method As Well Like Below
Storage::disk('s3')->putFileAs(
'file path',
$request->file('file'),
'file name',
[
'StorageClass' => 'STANDARD|REDUCED_REDUNDANCY|STANDARD_IA|ONEZONE_IA|INTELLIGENT_TIERING|GLACIER|DEEP_ARCHIVE',
]
);
I can't really find this answer on the internet. Hope it helps someone else.
If you want to set StorageClass on the disk level (once for every upload).
You can change it on the config\filesystems.php
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
'throw' => false,
'options' => [
'StorageClass' => 'INTELLIGENT_TIERING'
]
],
Other possible options...
'ACL',
'CacheControl',
'ContentDisposition',
'ContentEncoding',
'ContentLength',
'ContentType',
'Expires',
'GrantFullControl',
'GrantRead',
'GrantReadACP',
'GrantWriteACP',
'Metadata',
'RequestPayer',
'SSECustomerAlgorithm',
'SSECustomerKey',
'SSECustomerKeyMD5',
'SSEKMSKeyId',
'ServerSideEncryption',
'StorageClass',
'Tagging',
'WebsiteRedirectLocation',
Ref: thephpleague/flysystem-aws-s3-v3

ZF2 Doctrine2 Entity Cache

Does somebody know how to cache doctrine2 entities in a zf2 project. I cant find a tutorial or website where this is explained. I cant find any information to start with defining a entity filecache.
Somebody of you got working links or examples.
Thanks
You have two options
Use doctrine's native caching, e.g. using memcache (in the memcache block you can use any kind of doctrine supported cache, a full list of cache drivers is available).
Use doctrine's adapter for Zend/Cache/Storage to use another cache that you're using elsewhere; the adapter is described in the DoctrineModule docs.
As an example of version two, I have something like the following configuration in a module (actually spread across various config files, so I can't guarantee that copy-pasting verbatim will work).
'services' => array(
'factories' => array(
// Wraps a ZF2 cache storage in a Doctrine compatible way
'doctrine.cache.zend.static.local' => function ($services) {
return new ZendStorageCache($services->get('cache.static.local'));
},
),
'caches' => array(
// A ZF2 cache, can be configured as you like
'cache.static.local' => array(
'adapter' => 'xcache',
'plugins' => array(
'exception_handler' => array(
'throw_exceptions' => false,
),
'serializer',
),
),
),
'doctrine' => array(
'configuration' => array(
'orm_default' => array(
'metadata_cache' => 'zend.static.local',
'query_cache' => 'zend.static.local',
),
),
),
Note that Doctrine annoyingly automatically prefixes "doctrine.cache." to the name of the cache service that you configure, so while we configure "metadata_cache" to "zend.static.local", the actual cache service must be named "doctrine.cache.zend.static.local". Obviously you can call them what you want, but you'll need to add that prefix to whatever you call them.
To activate file cache you just need to add in your module.config.php
'doctrine' => array(
'configuration' => array(
'orm_default' => array(
'metadata_cache' => 'filesystem',
'query_cache' => 'filesystem',
)
),
)
and it will create cache automatically in data/DoctrineModule/cache folder
here is my full doctrine config for ZF 2.2.4 + Doctrine 2
'doctrine' => array(
'driver' => array(
'application_entities' => array(
'class' =>'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/Modulename/Entity')
),
'orm_default' => array(
'drivers' => array(
'Modulename\Entity' => 'application_entities'
),
)
),
'configuration' => array(
'orm_default' => array(
'metadata_cache' => 'filesystem',
'query_cache' => 'filesystem',
)
),
),

Magento - Install EAV Attribute via Installer

Hey guys im using the installer in my module to add a new EAV product attribute to the Default attribute set. So far its working great, but there are 2 little things that bother me.
public function getDefaultEntities(){
return array(
'catalog_product' => array(
'entity_model' => 'catalog/product',
'attribute_model' => 'catalog/resource_eav_attribute',
'table' => 'catalog/product',
'additional_attribute_table' => 'catalog/eav_attribute',
'entity_attribute_collection' => 'catalog/product_attribute_collection',
'attributes' => array(
'disable_sale' => array(
'group' => 'General',
'label' => 'Disable Sale',
'type' => 'int',
'input' => 'select',
'source' => 'eav/entity_attribute_source_boolean',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'is_visible_on_front' => true,
'used_in_product_listing' => true,
)
)
)
);
}
I want my attribute set to be visible on product details page and catalog listing per default.
'is_visible_on_front' => true,
'used_in_product_listing' => true,
The problem is that both values are not set to be visible.
What am i doing wrong?
I haven't done this with attributes per-se, but try both 'integers' 1 AND 'string' "1" in your code and see if it works.
is_visible_on_front change to visible_on_front and then check.
Found the answer here at stackoverflow:
Magento module setup/installer script
Setup class should extend from
Mage_Catalog_Model_Resource_Eav_Mysql4_Setup
Now the installer is aware of the additional attributes and its working like a charme.

Simultaneous ajax requests

I am trying to run the remote function in the code below every 5 seconds. It runs only once if I remove the frequency option. I tried remoteTimer function, but when I use remoteTimer function, some code of the script goes outside the script tags and I see that in the webpage.
echo $ajax->form(array('type' => 'post', 'options' => array('model' => 'Thing',
'url' => array('controller' => 'things', 'action' => 'xyz'),'update' => 'dy4', 'indicator' => 'ldng', 'loading' => ( $ajax->
remoteFunction(array('url' => array('controller' => 'stories', 'action' =>
'keep'), 'update' => 'dy3', 'frequency' => 5))))));echo $form->input('a', array('type' => 'checkbox'));echo $form->input('b', array('type' => 'checkbox')); echo $form->end('RUN');
If in case, this cannot be done using CakePHP helpers, how can I do it with JavaScript?
Use remoteTimer in a very simple controller. See the page source and between <script> tags you'll get code that does what you want.You can use that code as value for "loading" option.

Resources