I'm currently trying to prepare a view part into a variable but I must load the view part in a different language of the application.
I have my languages folder sets (french & english) and here what I tried with no success :
// Current language is french
$this->lang->load('[lang_file]', 'english');
$variable = $this->load->view('[path_to_view]', true);
$this->lang->load('[lang_file]');
First, is it possible to load another view in another language than the one currently in place ?
Second, if yes, what do I need to do ?
Thx.
Maybe temporary setting the language to english before loading the view file does the trick. Try this one:
$this->config->set_item('language', 'english');
$variable = $this->load->view('[path_to_view]', true);
If I'm not mistaken you should use $this->lang->load(), but maybe yours works aswell.
Bascily, yes it works. The lang keys will be overwritten, and new ones applied.
Do you have french as default language in your config/config.php?
And more importantly, is your view fetching data which the view uses before you run $this->load->language('[lang_file]', 'english');? There might be some passed errors from form_validation and simliar which will get the "wrong" language.
Related
i code a small very specific cms in php/mysql/jquery right now. the project have to be in german+english - so store these informations in separate fields : title_de, title_en ..., category_de, category_en and so on. pretty easy.
now there will be some fields for html content where i have to store a combination of unordered image + text combinations. i do it like this right now :
<img>text<img><img>text<img><img>text<img>text<div>otherstuff</div>text<img>
so pretty random html elements no structure ...
so a user will have to copy this structure after creating it to another text-area for another language and translate it.
i dont like the idea to store the "structure" and the "double parts e.g. the images" twice . this would work for 2 languages - but what if its 10 languages.
is there an logic and easy way to separate the structure and how would you model that in a database ?
I think what your looking for is called as internationalisation and localisation.
For that you may not create any new column or any other tables in database. Even you can handle with language file. Since you told that yours is small project it will work fine.
You should really use any good library like https://github.com/Philipp15b/php-i18n which is having good attention in git hub.
Even I have a solution of using basic one.
NOTE : Since I wont be using any caching technique to save the
languages there may be performance issues. Please note I will recommend using any good library. Mine is just an idea for the sake of implementation. You can enhance based on it.
en.php
$language = array(
'Hello' => 'Hello!',
'HtmlText' => '<h1> HTML </h1>'
);
fr.php
$language = array(
'Hello' => 'Bonjor'
'HtmlText' => '<h1> HTML </h1>'
);
In your page now you can implement the following way
Eg:
Advice : Make sure you handle your HTML encoding while displaying.
/* Validate whether $_GET['lang'] is set or not.
Whether your havig any language of that specif or not
Then use the following way to implement
*/
URL : http://127.0.0.1/project/?lang=en
include_once $_GET['lang'].'php'
echo $language['Hello']; //Irrespective which ever language you use it will load
We have received below errors on the home page:
eZTemplate # design/dffestival/templates/page_footer.tpl:8[6]:
Unknown template variable 'view_parameters' in namespace ''
In our pagefooter.tpl file have below code:
<div class="attribute-layout">
{attribute_view_gui attribute=$footerNode.data_map.layout view_parameters=$view_parameters}
</div>
We are using eZ Publish Community Project 2012.6 version.
Could anyone explain why I can't retrieve the view_parameters variable and how to do retrieve it?
Thanks
Sunil
Maybe u should start here:
http://www.ezpedia.org/ez/view_parameters
Remember view parameters are by default available only within the
context of the content module and it's views.
All other modules (by default) do not support this feature.
The recommended alternative to view parameters in these situations
would be using get / post parameters instead.
Or here:
https://doc.ez.no/eZ-Publish/Technical-manual/4.x/Templates/Basic-template-tasks/Custom-view-parameters
In some cases $view_parameters won't work, try
$module_result.view_parameters there. So the example above will be:
The color is: {$module_result.view_parameters.color} The amount
is: {$module_result.view_parameters.amount}
Or here (check "$module_result section"):
https://doc.ez.no/eZ-Publish/Technical-manual/3.10/Templates/The-pagelayout/Variables-in-pagelayout
Short answer :
You are trying to retrieve the $view_parameters within the pagelayout (or a template included in it). This is not possible by design and this is completely normal.
Long answer :
View parameters are meant to be used from the views/templates which are used by the content module : for instance, when viewing a content from its alias URL or using its system URL like /content/view/full/2.
They are useful if you want to pass some parameters from the URL to the content view and they are taken into account by the cache system which is a very important thing to keep in mind (this is not the case when using "vanilla" GET parameters).
The main usage is for pagination, for instance : /content/view/full/2/(offest)/2/(limit)10
One of the best practices when developing with eZ Publish (legacy) is to ask yourself : why do you need to retrieve these parameters into your layout ? I guess that you want to control your global layout using them and this is not a good idea.
If you want to control the layout based on something which depends on the content, then I'll suggest to use persistent variables. You will basically use the ezpagedata_set operator in the content/view template and retrieve this value in your pagelayout with ezpagedata() | see https://doc.ez.no/doc_hidden/eZ-Publish/Technical-manual/4.x/Reference/Template-operators/Miscellaneous/ezpagedata_set
Last but not least, remember that the module result is computed before the pagelayout (simply because the pagelayout will include this result using $module_result.content).
I am using Yii framework to develop a multilingual web site. Right now I have English and French versions. I have created a fr folder and placed views and controllers related to French version, but using same models for both versions.
My database tables structure (articles table) is:
id, title_en, title_fr, title_ru, detail_en, detail_fr, detail_ru and
so on.
The issue I am facing is that I need to display error messages to the users in respective languages like in French version error message should be in French. How can I do while using same model for all languages.
Where do I need to put the French messages?
I don't know, if I'm getting you correct, but if I understand your question, your problem is already solved by core Yii 1.x engine and there isn't much work left to do.
In detail, you have to:
Create any file (for example app.php) in /protected/messages/fr/ folder.
Put 'coreMessages'=>array('basePath'=>'../protected/messages'), to your application's configuration array -- route Yii translation system to folder with your customized translations.
Put 'sourceLanguage'=>'en' to your configuration array -- make sure, that your applications's core language is set to English.
Fill app.php file with your translation strings (see below).
Translate parts of your application with Yii::t('app', 'string'); (see below).
Your translation files should be in format:
return array
(
//Translations from Google Translate! :> I don't speak French at all! :>
'This page is not yet translated into your language.'=>'Cette page n'a pas encore été traduit dans votre langue.',
'Language'=>'Langue',
'read more'=>'en savoir plus'
);
So, for example, but in your blog list view string like:
<?php Yii::t('app', 'read more'); ?>
When you set your application language to fr, either by forcing it in code (Yii::app()->language = 'fr';) or presetting it in appliction's configuration array ('language'=>'fr'), you should see en savoir plus (or whatever you put to your translation file) in place of read more in above view.
If your application's language is set back to English or if given translation string is not found, you'll see text written in Yii::t. That's why it is so important to use fully qualified English strings in this method (and in translation files) and to avoid "patterns", like 'core.app.language'=>'Langue' etc.
Note, that you can also use parameter placeholders:
'Error no {code}:'=>'Erreur n {code}:'
that will be replaced with the actual parameter values:
Yii::t('app', 'Error no {code}:', array('{code}'=>$code));
This way you can provide variable values to otherwise constant message text.
There's a great topic about internationalization in "The Definitive Guide to Yii". You should read it through for more information on this matter or, if you want to use Yii translation mechanism in a bit more advanced way.
You can override CPhpMessageSource::loadMessages() with something like following:
protected function loadMessages($category,$language)
{
if ($category == 'yii')
return array();
else
return parent::loadMessages($category,$language);
}
Also You can change the language, set CApplication::language appropriately. This can be done at runtime as in
Yii::app()->language = 'fr';
i am beginner in yii framwork
i want to change language in my project i tried but it was ineffective
i explain steps then u help me and tell my wrong
i did:
add 'sourceLanguage'=>'en_us', and 'language'=>'fa-ir' in \protected\config\main.php copy fa-ir folder fromyii\framework\messages
copy to myprojectname\protected\messages
add to myprojectname\protected\views\site below code
$lang = Yii::app()->language;
echo "my lang is:::::".$lang;
Yii::t('zii','Delete');
Yii::t('yii','Get a new code');
my language has been change but i have not any result
i think i must to clean catch files in directory
you can follow this link for guid through setting up your language support.
have you done setting up your message folder?
Change language in YII
this link is good for maintaining a language support
I'm trying to get CakePHP's i18n component to work. I have extracted my strings to app/Locale/default.pot using the i18n console task. I then copied it into app/Locale/eng/LC_MESSAGES/default.po and app/Locale/fra/LC_MESSAGES/default.po making sure to change the extension. I used the program Virtaal (similar to Poedit) to translate some of the strings.
In my app/Config/core.php I have set my default language to english with Configure::write('Config.language', 'eng'); if I change it to Configure::write('Config.language', 'fra'); I expected to see the new translated strings but nothing changed. I tried setting the Config.language key in the session as well but it didn't do anything. Printing out the configure value and session values I can see they are being set.
Am I missing something here? also in the many different posts I've been reading about i18n in CakePHP I've seen the key fre being used interchangeably with fra is there a difference?
After http://book.cakephp.org/1.3/en/The-Manual/Common-Tasks-With-CakePHP/Internationalization-Localization.html it should be fre for french.
// locale path
/app/locale/fre/LC_MESSAGES/default.po (French)
// To change or set the language for your application, all you need to do is the following:
Configure::write('Config.language', 'fre');
// To set the language for the current user, store the setting in the Session object, like this:
$this->Session->write('Config.language', 'fre');
Further than that:
In our cakePHP application I have to restart the apache webserver after changing the files to get the new strings because of caching. Perhaps you have to do that too, but I'm not quite sure as we generate .mo files out of the .po via an POEdit setting. I dont't think you are forced to do this, because the cookboke doesn't say anything about that (or I didn't found it now :D ).
edit:
Looks like cake is using the bibliographic codes for french but the terminology for german. That's very confusing :/ : http://www.loc.gov/standards/iso639-2/php/code_list.php