i', trying to incorporate multi-language functionality into my project and i have a situation whereby the same key has multiple meaning and i wounder how to fix this for example i have in my project
return[
'Home' => '首页', //meaning ‘Home page’
]`
Now the case is i also have some over words with Home as the key but have another meaning like thus
'Home' => '主队', //meaning ‘Home team’
how can actualize this using the same key "Home" but giving them different meaning on different part of my project
There are two options how to deal with situation like that.
Using categories
The proper way would be using different categories for different meanings. To do that you have to configure the translations for two (or more) different categories, for example like that.
'components' => [
// ...
'i18n' => [
'translations' => [
'app*' => [
'class' => 'yii\i18n\PhpMessageSource',
'fileMap' => [
'app' => 'app.php',
'app/match' => 'match.php',
],
],
],
],
],
Your app.php translation file will look like this
return [
'Home' => '首页', //meaning ‘Home page’
];
And your match.php translation file will look like this:
return [
'Home' => '主队', //meaning ‘Home team’
];
Then you will call translations like this where the meaning is home page:
Yii::t('app', 'Home');
And like this where the meaning is home team:
Yii::t('app/match', 'Home');
If you are using yii message command to generate translation files you might need to set the fileMap in it's config to make sure all files are generated properly.
Forcing translations for source language
This way is more like hack than proper solution. You can force the i18n component to translate text even if the source and app language are same. You can use that to have two different keys that are same in the english translations but different in other.
The configuration would look like:
'components' => [
// ...
'i18n' => [
'translations' => [
'app*' => [
'class' => 'yii\i18n\PhpMessageSource',
'forceTranslation' => true,
'fileMap' => [
'app' => 'app.php',
],
],
],
],
],
The english app.php translation file:
return [
'Home page' => 'Home',
'Home team' => 'Home',
];
The chinese app.php translation file:
return [
'Home page' => '首页',
'Home team' => '主队',
];
You will use Yii::t('app', 'Home page') or Yii::t('app', 'Home team') in your code.
Related
To better understand the code of MediaWiki, I'm trying to modify directly the source code without creating an extension.
In the page Special:Categories I'd like to show only the categories which are not created by a Template. How can I modify the query?
https://doc.wikimedia.org/mediawiki-core/1.28.0/php/classSpecialCategories.html
https://doc.wikimedia.org/mediawiki-core/1.28.0/php/classCategoryPager.html
I've found the solution
The source code for the Special Pages is inside the folder includes/specials. There are many scripts here about categories and by comparing some of those files I could find out the syntax used to manipulate queries in mediawiki which is defined through the method getQueryInfo() inside each file.
I'm posting the queries defined each in a different Special Page related to categories
public function getQueryInfo() {
return [
'tables' => [ 'category' ],
'fields' => [ 'title' => 'cat_title',
'namespace' => NS_CATEGORY,
'value' => 'cat_pages' ],
'conds' => [ 'cat_pages > 0' ],
];
}
public function getQueryInfo() {
return [
'tables' => [ 'categorylinks', 'page' ],
'fields' => [
'namespace' => 'page_namespace',
'title' => 'page_title',
'value' => 'COUNT(*)'
],
'conds' => [
'page_namespace' => $this->namespaceInfo->getContentNamespaces()
],
'options' => [
'HAVING' => 'COUNT(*) > 1',
'GROUP BY' => [ 'page_namespace', 'page_title' ]
],
'join_conds' => [
'page' => [
'LEFT JOIN',
'page_id = cl_from'
]
]
];
}
I want to overwrite a css code of an existing asset, for example “kartik\form\ActiveFormAsset”. If i follow the official guide, i will do this:
'components' => [
'assetManager' => [
'bundles' => [
'kartik\form\ActiveFormAsset' => [
'sourcePath' => null, // do not publish the bundle
'basePath' => '#webroot',
'baseUrl' => '#web',
'css' => [
'/custom.css',
]
],
],
],
],
But it automatically changes a path to a js file which i want to keep up-to-date and don’t do any changes.
So, how to overwrite asset only for css, not for js?
If you don't need an asset assignment or you want overwrite the assignmente you could try using registering scripts in your view .
$this->registerCssFile("#web/css/themes/black-and-white.css", [
'depends' => [\yii\bootstrap\BootstrapAsset::class],
'media' => 'print',
], 'css-print-theme');
see yii2 guide and reference for this
https://www.yiiframework.com/doc/guide/2.0/en/output-client-scripts
https://www.yiiframework.com/doc/api/2.0/yii-web-view
I have the following URLs:
http://test.local/index.php?r=site%2Findex&slug=blog-detail
http://test.local/index.php?r=site%2Findex&slug=blog
http://test.local/
I want to get:
http://test.local/blog
http://test.local/blog-detail
http://test.local/
I am sending all requests to SiteController::actionIndex($slug), I am using Basic Application Template.
So far, I have been able to hide index.php and site/index.
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<slug\w+>' => 'site/index',
],
]
But it seems \w+ does not match strings with -. Also if slug is empty it should show: http://test.local/.
\w does not match -. You need to use [\w\-] instead. And + requires at least one char in your case. You should use * instead:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<slug:[\w\-]*>' => 'site/index',
],
]
What you are trying to make is make specific url based on GET param. With the following example if the user enters url test.local/Some-nice-article then the SiteController::actionIndex($slug) function will get the param.
'urlManager' => [
'pattern' => '<slug>',
'route' =>'site/index',
'ecnodeParams' => false,
//class => any\custom\UrlRuleClass,
//defaults => []
]
Or you want another url to specify whether it is detailed view? You can do it this way:
'urlManager' => [
'pattern' => '<slug>-detail',
'route' =>'site/detail',
'ecnodeParams' => false,
//class => any\custom\UrlRuleClass,
//defaults => []
]
In this example, if the users puts the string '-detail' at the of the slug, then it will parse the route SiteController::actionDetail($slug) to the request.
Please note that if you did not yet, enable prettyUrls in the config file
You can find a little more about this topic in this answer or in the Yii2 definitive guide
I have changed nothing in my config file, and maybe because of an update or I don't know, I realized that translations doesn't work anymore.
'components' => [
'i18n' => [
'translations' => [
'*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#app/messages',
'fileMap' => [
'yii' => 'yii.php',
],
],
],
],
I have tried with '*' =>, 'app' =>, 'app*' =>, nothing is working, and I've tried to search but found nothing relevant. There are no error messages, except a warning for rbac-admin:
warning: The message file for category 'rbac-admin' does not exist: .../vendor/mdmsoft/messages/de/rbac-admin.php
however it's there, but it doesn't really matter at the moment.
Can you please point me to the right direction? Thanks a lot!
I use export menu on my yii2 project. I download it from demos.krajee.com. I have been success to use it, but I want to edit content like in pdf, so it have title/header or footer or page number. How to make it?
There are at least two ways to do that.
For example you can set it as default setting in
Yii::$container->set('kartik\grid\GridView', [
'summary' => "Showing {begin} - {end} from {totalCount} records",
'captionOptions' => ['style' => 'font-size:0em;'],
'panel' => [
'heading' => false,
'before' => '{summary}',
'after' => '{pager}',
'footer' => false,
],
'hover' => true,
'toolbar' => [
'{export}',
'{toggleData}',
],
'export' =>[
'showConfirmAlert' => false,
],
'exportConfig' => [
kartik\grid\GridView::PDF => [
'label' => 'Save as PDF',
'config' => [
'methods' => [
'SetHeader' => ['Header'],
'SetFooter' => ['Footer whatever: ' . strftime("%c") . '||Page {PAGENO}'],
]
],
],
],
...
Or pass the settings individually to each widget in every view.
You can use methods in wrapper http://demos.krajee.com/mpdf#settings (look for methods) or directly from mpdf class if you need something more complicated.