Jump to content

Recommended Posts

HI all,

 

I know not much about php, but i thought before i start creating a nice application that is useful, i ask a bit around for advice. I was thinking that it could very well be smart to make something like a language file. In that file are for instance the names of table headers, error messages, button text etc. I thought that would be nice because that way i can easily translate a complete site, by using just one file, a language file.

 

I thought i could use define() in that file to create some constants like:

define("invalidname", "the name you provided is invalid");

Than In my index I include that file and use the constant in the right places.

 

 

Now the question i have is, would this dramatically slow down my website or application, because it's loading the language file. Or is it a good approach.

I really have no idea, but it seemed to me like a nice idea to separate standard stuff like errors, and button text instead of having to edit all files separately.

 

Love to hear tips and advice, better methods on this.

thanks ::)

Link to comment
https://forums.phpfreaks.com/topic/231016-a-multi-language-approach/
Share on other sites

I wouldn't go and use definitions.. Here is a good article about localization in PHP:

http://docstore.mik.ua/orelly/webprog/pcook/ch16_01.htm

 

It's not by any means too comprehensive.. But there are atleast things I've found useful. Defining your languages to array is a basic easy-approach solution. But if you want performance, use gettext() or the alias _() and manage your language files through your command line or use something like Poedit to make it a little easier. Take a good look at internal php localization; setlocale(), date_default_timezone_set() combined with the right functions ie. time functions are very important to use to provide everyone information in their own national date/time format and weekday names etc etc. Like strftime() will create a date for you according to your locale.

 

An article to set you up with using gettext: http://onlamp.com/pub/a/php/2002/06/13/php.html

Poedit site: http://www.poedit.net/

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.