Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Languages and templates
Old 06-16-2008, 07:06 PM Languages and templates
Banned

Posts: 32
Trades: 0
I was thinking about the best way to combine templates and language files.
Shall i keep the text/sentences/expressions inside each template or keep it separate?

- If i keep the template with the text i need to set 1 template version for each language (if you change tamplate A structure for 1 language you need to change it to all the other languages).
PHP Code:
[english]
$template '<div>
<span class="little">This is Text</span>
</div>'
;
[
spanish]
 
$template '<div>
 <span class="little">Esto eres texto</span>
 </div>'
;
..
.. 
- If i keep it separate its more efficient yet its very user unfriendly because people will see only references to the texts and it might become confusing.
PHP Code:
$template '<div>
<span class="little">'
.$text['342'].'</span>
</div>'

A dilemma

Last edited by Elenis; 06-16-2008 at 07:12 PM..
Elenis is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-17-2008, 03:37 AM Re: Languages and templates
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
You could just place all the words for each language in an array and make the user say what language they want. For example:
PHP Code:
$lang[english][hello] = "Hello";
$lang[french][hello] = "bonjour";
$lang[spanish][hello] = "hola";

// User defines what language
$language "english";

// Say hello
echo $lang[$language][hello]; 
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 06-17-2008, 03:53 AM Re: Languages and templates
Banned

Posts: 32
Trades: 0
Whats the difference from your post and my 2nd example? o_o
Elenis is offline
Reply With Quote
View Public Profile
 
Old 06-17-2008, 03:59 AM Re: Languages and templates
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Mine uses an deep array, your uses numbers :P

*[sarcasm] Blatantly did not just guess the answer to your post *
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 06-17-2008, 08:46 AM Re: Languages and templates
Banned

Posts: 32
Trades: 0
Lol, i would i want to write a text code for thousands of language lines? a number is way easier...

anyways, guess i will have to compromise friendliness to achieve efficiency.

Last edited by Elenis; 06-17-2008 at 08:48 AM..
Elenis is offline
Reply With Quote
View Public Profile
 
Old 06-17-2008, 12:59 PM Re: Languages and templates
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
I have a couple of principles for supporting multiple languages:

1) Load only what's necessary, and
2) Reference using the language code (see http://www.w3.org/TR/REC-html40/stru...g.html#h-8.1.1 ). For example, "en", "fr", "es"

That said, it is generally not necessary to load a translation for every language -- most of the time the primary language of the site visitor suffices. To accomplish this, a modification of the multidimensional array above suffices:

Filename: en.php
PHP Code:
$lang['hello'] = 'Hello'
Filename: fr.php
PHP Code:
$lang['hello'] = 'Bonjour'
Filename: es.php
PHP Code:
$lang['hello'] = 'Hola'
PHP Code:
// User defines what language
$language "en";

require_once(
$language.'.php');
// Say hello
echo $lang['hello']; 
In my sites, I generally have multiple pages, so I create a core language file (as shown above) which includes text which shows up on more than 1 page and then a language file for each page which includes the text for that page which is not in the core file. This minimizes the amount of memory necessary to create each page.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 06-17-2008, 01:01 PM Re: Languages and templates
Arenlor's Avatar
Ultra Talker

Posts: 462
Name: Jerod Lycett
Location: /home/arenlor
Trades: 0
Text codes already exist... http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Old 06-17-2008, 06:38 PM Re: Languages and templates
Banned

Posts: 32
Trades: 0
You didnt follow my topic: combination of languages and templates..you only refer to languages...

Quote:
Originally Posted by JeremyMiller View Post
I have a couple of principles for supporting multiple languages:

1) Load only what's necessary, and
2) Reference using the language code (see http://www.w3.org/TR/REC-html40/stru...g.html#h-8.1.1 ). For example, "en", "fr", "es"

That said, it is generally not necessary to load a translation for every language -- most of the time the primary language of the site visitor suffices. To accomplish this, a modification of the multidimensional array above suffices:

Filename: en.php
PHP Code:
$lang['hello'] = 'Hello'
Filename: fr.php
PHP Code:
$lang['hello'] = 'Bonjour'
Filename: es.php
PHP Code:
$lang['hello'] = 'Hola'
PHP Code:
// User defines what language
$language "en";

require_once(
$language.'.php');
// Say hello
echo $lang['hello']; 
In my sites, I generally have multiple pages, so I create a core language file (as shown above) which includes text which shows up on more than 1 page and then a language file for each page which includes the text for that page which is not in the core file. This minimizes the amount of memory necessary to create each page.
Elenis is offline
Reply With Quote
View Public Profile
 
Old 06-17-2008, 07:19 PM Re: Languages and templates
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Well, what do you want to do with a template? I usually create 1 file and include the language stuff in there -- this code
PHP Code:
// User defines what language
$language "en";

require_once(
$language.'.php');
// Say hello
echo $lang['hello']; 
</span></span>
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Reply     « Reply to Languages and templates
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.35030 seconds with 12 queries