CodeIgniter – frontend language files editor
I was looking for frontend language files editor suitable for my needs. Unfortunately I failed to find a solution that suits me ( maybe type-o in keywords ;o) ). Therefore I decided to create my own piece of code.
Hence I present my little contribution to CodeIgniter.
Now you can find this project on github! :o)
Frontend Language Files Editor on github
Basic idea
- Using Language Class my files for language are stored in /my_application_folder/language/.
- I want edit all pairs key=>value for languages without opening my file. Add new keys which will be enable for another languages.
- I want to create new languages, new files and copy structure of file to another language.
- I want to delete languages or files.
- I want to delete one key from all files and from database.
- I want to remove keys from database for file if file does not exist in other languages.
- I want to create backup file just in case.
So basically keys will be stored in database. If I add new key, save file in which I add it, and then go to edit this file in other language that new key will show up in form. But remember, new key physically will not be in another languages files until you save them.
Requirements
Codeigniter 2.x, jQuery
Installation
Grab it from github and extract to corresponding folders.
Be aware that there is application/core/My_Lang.php file, so if you use i18n for multilanguage most likely you have MY_Lang in that folder already. So be sure that you want to overwrite it.
How it works
You call it by entering address: http://yourdomainhere/language/
The list of languages are created by folder structure in /my_application_folder/language/.
The list of files are created by content in language directory. Only .php files are considered and backup files are excluded.
When you choose some file for the first time (keys are not in database) you will be asked if you want to add them.
If there are some differences between keys in file and keys in database we have two options.
- Some keys exists in file and not in database – you will be asked if you want to add them. Until than, that keys will not be available in form. Warning! If you save your file before adding those keys, the translation and key will be erased from the file.
- Some keys exists in database and not in the file – you will see (NEW!) next to key name. You will see that most likely when new key was added to the file in other language.
In case anything goes wrong (I hope not) I added copy function which creates backup file so you can restore last file after crash. Better be save than sorry ;o)
If you delete key from file it is also deleted from other languages and database.
All translations are escaped by addslashes php function. So if you’re using $this->lang->line(‘key’) and there was some escaping, remember to use stripslashes before you echo $this… You could also use core/My_Lang.php file which already has it. Then you don’t have to worry about that.
If you have CSRF protection on – remember that it has expire time – so don’t edit your files too long ;o)
I assume that if you want a line break in your translation, you need to add <br/> tag.
This frontend already use language class. All buttons, information etc are already put into language_lang.php file so you can translate it into your language.
If you have some questions/suggestions/problems feel free to ask.
An Amazing work, thank you very much!
I made one for CodeIgniter 3 based on the same concept as Eliza did (not knowing it before). Congrats BTW.
https://github.com/jmendoza-es/CodeIgniter-3-Translation-Interface
This has a nice UI that could make creating multilingual site in CodeIgniter easier. However, manual method is not that difficult to begin with, if you know how to work with language classes in CodeIgniter. Here is an example: https://www.cloudways.com/blog/multi-language-codeigniter/
Hi I found an error it is throwing
A PHP Error was encountered
Severity: Runtime Notice
Message: Declaration of MY_Lang::line() should be compatible with CI_Lang::line($line, $log_errors = true)
Filename: core/MY_Lang.php
Line Number: 26
Backtrace:
Also have you thought about putting an auto translate through it?
i also getting this error
u got any idea now?
Change line function parameter at line 13
and add parameter $log_errors = true of MY_Lang.php file stored in application/core/
I cannot make it work on CodeIgniter 3, even doing migration steps… Any help?
Loved your interface :) You use simple file_get_contents() file_put_contents() and line parsing here right? I was thinking to write something like that for my application, so I came by. See ya.
Good work,
Line 281 in language controller should be changed to redirect("/language"); Otherwise it does too many redirects and error language_error_creating_permissions is not displayed. It tried to redirect to the file it could not create.
Hi ya, loving this:
Just made a slight adjustment, which others may benefit from to hide things like .svn folders
model_language.php Line number: 26
CHANGED FROM:
if($filename!=='.' && $filename!=='..' && is_dir($dir.$filename)){
TO:
if($filename!=='.' && $filename!=='..' && $filename!=='.svn' && is_dir($dir.$filename)){
nice tool, will try it and write some feedback on github.
gonna test it, i hope it gonna work.
it could safe a lot of time!
thanx
Hi, arif.
If file doesnt exist for some language you just need to go to edit mode for it. there will be button create. you can see it here http://img443.imageshack.us/img443/5650/showr.png
When you click it file will be cloned with its content to that language. I dont know if that is what you want.
Unfortunately Im stuck with some projects and dont have time to work on this. :o(
hello i have one question did you add a function so that old language file can be cloned from admin and then translate them . suppose there will be a button translate that will search google api for translation and then show the translation text there.
if you have not time then we will try to implement that.
z3phir.
not yet. But soon will be. I just don’t have much free time ;o)
thanks for your work
very nice this could be very usefull
it supports arrays ?
i will follow this next upday …
Glad i could help :o)
just try and HOOORRAAA work perfect !!!
thank to answe fast!! i will look tonight
i thing i will go for the first solution, this type of files “seting” is only for administrator.
So, you have two options.
One. Add “language” controller to $special array in application/core/MY_Lang file. By doing it the i18n will not add language to url when you use this interface, so there will be no redirects.
Two. Change links in view files by adding $this->lang->lang() after base_url() to all links. So for example link to action for adding keys for first time in edit_lang_file would look like this:
action=”<?php echo base_url().$this->lang->lang();?>/language/update_all_keys”
If you will go with second option, you’ll have to change all links in all view files for interface.
yes i use i18n !
i do not understun all, but my url become
“http://localhost/test/fr//language” after i clic on yes.
it shud not with codeigniter.
hi, zorg,
Do you use some kind of language library for your CI? like i18n ?
I had similar problem with it, just after adding i18n. Check in firebug if you don’t have some kind of redirect from POST to GET. That could happen if the library add two letters to your url address if address don’t have it.
If it’s not the problem, in firebug you should see if data is properly send as post. Let me know if that helps.
hi first sorry for my poor english :)
this is he great application !!
but i have he probleme, interface work well, but if i try to open for the first time the files “english -> ftp_lang.php” and i clic “yes” it gave me this error “No direct access allowed”.
thank for your application.
Hi al,
It’s not quite a mistake. Although i forgot to remove $new_keys=”; just before foreach loop. So thank you for pointing that out :o) the zip file has been updated
If no new_keys have been added then this variable isn’t set, OR if there is I need to check if it’s not empty and if it’s array. Just in case ;o)
With that said, you should notice that in foreach loop I check if new key already exist in file. If is then this key is skipped. Later I will add something to controll duplicate keys.
Hi. Big tool. Thanks.
I believe you have a mistake in your controller, line 176:
if(!isset($new_keys)….
Should not be? If isset, not if isnt isset?
if(isset($new_keys)…
Files are online again :o)
Please, can you put online the files again. Thank you!!!