I am looking to find a good way to create an http editor to manage CI language files ... ( for a custom made CMS )
I found following project but its a bit old and buggy :
http://www.mrkirkland.com/codeigniter-language-file-translator/
also it doesnt support of adding new language file and language key...
///
I am thinking of a new way for making it much easier to manage CI languages with mixing mysql and CI language files ...
there will be two tables ( lang / translations ) in the mysql table and a controller for http gui...
each time the editor finished her/his translation job her/she will click on Finish button and it will output CI language files in different languages ( but each language in a same file )
with this way We are using native CI Language system (which is fast) and managing/searching/editing of translations are much easier than directly editing CI Language files ... also its much secure ...
example :
TABLE : langs =
lang_id ---- lang_name
1---- English
2 --- German
TABLE : translations=
key --- lang_id --- translation
hello --- 1 --- hello
hello --- 2 ---hallo
and the output will be these files
/application/language/english/global_lang.php
$lang['hello'] = 'hello';
/application/language/german/global_lang.php
$lang['hello'] = 'hallo';
what is your opinion ? does it worth to do this ?
I found this:
http://blog.codebusters.pl/en/entry/codeigniter-frontend-language-files-editor
Hope this helps
:)
For php language file editing I'm using this Firefox addon: https://addons.mozilla.org/en-US/firefox/addon/phplangeditor/
It's easy to find untranslated strings...
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
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'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
I am developing a multi-langual website. Language variables (phrases/word translations) will be entered in a specific file (one different file for each language)
I wanted to know the best way to enter the phrases/word translations, should I use a normal array?
e.g
Filename = English.php
<?php
$translations = array();
$translations['phrase1'] = "this";
$translations['phrase2'] = "that";
..
?>
and in the template file
<?php
include("English.php");
echo $translations['phrase1'];
etc...
I am pretty new to PHP so I am just looking for the best way to do it.
Any suggestions?
Thank you for your help!
There are multiple of ways to do this, the two things that pop-off my head right now are:
1) Have a look at gettext & GNU gettext page. An example implementation of this to look at is Aur Website of ArchLinux. They their app support multiple languages & its all dynamic. user can can switch between languages easily. The source code is available here, study it & see how they did it.
2) Other option could be use a framework like cakephp, as most of these frameworks have translations support
Hope it somewhat helps
I'm trying to find the best way of structuring a multi-language site navigation,.
I'm aware of the language class in CI but it seems to be more for defining random words and lines of text that are used commonly throughout the site. It appears that creating lang files for each language and then defining translations of all the links seems like the standard approach?
In past on non-codeigniter projects I’ve setup one class like this
class Link{
var $name = array();
var $url;
var $links = array();
function add_link($links){
$this->links[] = $links;
}
}
$all_sections = array();
$section = new Link();
$section->name['en'] = "Home";
$section->name['fr']] = "Uberdurky";
$section->url = "/";
$sub_section = new Link();
$sub_section->name['en'] = "About Acme Ltd";
$sub_section->name['fr'] = "Fabuka Acme Ltd";
$sub_section->url = "/about/";
$section->add_link($sub_section);
Then I have a function to loop through and output the nav, which just looks at the current name[Lang] as defined by session or URL
This to me seems simpler and less overhead - with the benefit that both the nav structure and translations are defined in one place. But I’m new to CI so I might be misunderstanding the standard approach… ? I've googled quite a bit and haven't seen a solution here in detail.
The important thing is that it works for you. There are a lot of benefits to using separate language files:
Clean separation
Only load what you need
Easy to keep track of which languages are available
Ability to let others easily translate the files
I don't see anything wrong with the way you're doing it, but if you want to optimize - don't bother defining all the different language lines. You don't need the French version defined if the language is English. Use only the ones you need, you shouldn't have to pass the whole array to add_link(), the Link class should be detecting the language and loading the appropriate array only...
...it's starting to sound like a language file might be a good idea actually.
For now you just have French and English. I'm assuming you know both languages and (Uberdurky?) are the only one working on this aspect, so it's easier for you to define them "inline". What happens when you want to support 3, 4, or 10 languages? Things will quickly become disorganized and cluttered.
However, you don't have to use the Codeigniter Language class, you might be better off using your own system for something like navigation, which tends to be littered with 1 or two word translations, and changes somewhat frequently (either per site or between sites).
Once again, it's your call. Do what works best for you now and optimize later.
This might be helpful to anyone coming across this question.
https://github.com/cflynn07/CodeIgniterInternationalizationUtility
It's a script to take a cleanly structed HTML table of language translations, and convert them into the required language files used in codeigniter.