arne-s / jstrans Goto Github PK
View Code? Open in Web Editor NEWUse Yii translations in JavaScript
Use Yii translations in JavaScript
This is what I have in config
'preload' => array('log', 'jsTrans'),
'components' => array(
'jsTrans'=>array(
'class'=>'application.extensions.JsTrans.JsTrans',
'categories'=>array('frontend', 'backend'), // the categories to be made available
'languages'=>array('en', 'fr'), // the languages to be made available
),
the dictionary files are created in assets folder.
I have this structure for messages
protected/
and is working fine in php, But when I try in JavaScript with JsTrans I can access only variables from frontend
Yii.t('frontend', 'TRANS_VARIABLE') - working fine
Yii.t('backend', 'TRANS_VARIABLE') - not working
even though TRANS_VARIABLE exists in both frontend and backend
Can you help me please.
Can you please point me to the right direction? I have a Yii project and translation is generated using yiic. I am able to generate string with Yii.t translator.
In JS files I have alert(Yii.t("translate","Your message has been sent successfully"));
I installed your extension this way
Yii::setPathOfAlias('extensions', dirname(FILE).'/../../../extensions');
'import'=>array(
'application.models.',
'application.components.',
'extensions.JsTrans.*',
),
'jsTrans'=>array(
'class'=>'extensions.JsTrans.JsTrans',
'languages'=>array('en','es'), // the languages to be made available
),
So the confusing part for me is this line in the README file
new JsTrans('app','nl');
Where do I need to put this line of code to work correctly with yiic?
Translations consisting out of # characters only should be ignored
I added
public function actionMissingTranslation($category, $message, $language) { Yii::t($category, $message, null, null, $language); }
in controllers/SiteController.php
and my config is
'jsTrans'=>array( 'class'=>'ext.JsTrans.JsTrans', 'categories'=>array('app'), // the categories to be made available 'languages'=>array('fr','es'), // the languages to be made available 'onMissingTranslation'=>array('site/missingTranslation'), // optional route to handle untranslated messages ),
When I acces site/missingTranslation it gives Error 400: Your request is invalid.
Can you tell how the url should look like?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.