1

I have made one language file,. It will look something like this.

lang.php
define('lang_var_1','english');

now I want a function that can replace 'english' to other value.

Rukmi Patel
  • 2,619
  • 9
  • 29
  • 41
  • Take a look at this SO post: http://stackoverflow.com/questions/1414079/most-efficient-way-to-do-language-file-in-php – Bjoern Mar 06 '12 at 05:27

2 Answers2

1

My Suggestion is make multiple language files one for each language. Each file essentially looks the same except the translation itself. But they all share the same definition for that translation. You would then make a function that would load the given language file of choice.

However you always want one default language pack. Reason for this is when you load a language pack and your rendering whatever where ever if the definition your looking for either doesn't exist in one language pack or has no value cause the translation hasn't been found yet you want to revert to a pack that does have a translation for everything so your not left with empty gaps.

chris
  • 36,115
  • 52
  • 143
  • 252
  • Well I have made separate files for different languages. I want to change the existing language constants.by fopen in w mode i can write the file but i can not append the file content. what i should do to append the file content. ? – Rukmi Patel Mar 06 '12 at 05:36
  • can you edit your original post to show how you are reading/writing to the file currently? – chris Mar 06 '12 at 05:38
0

you can set a variable instead of defining language as constant

lang.php
define('lang_var_1',$language);

then give a choice to users to select which languages they want to use.Afterwards you can get that value and set $language to that value. Here you go.