|
Posted by Rik on 10/19/06 06:20
linda wrote:
> Hi Frits and welcome
> to the wonders of php. I too am new to php.
And Frits is battling with the same page since februari this year (or
earlier?)... Not exactly new, but takes on a lot of known difficulties ;-)
To maybe give Frits a few pointers (I do admit I haven't read this thread,
so possibly there's an overlap with other posts/possibly better solutions):
- I use TinyMCE to give users the possibilities to edit pages. Do not try
to let them be translated tag by tag. If the users put a 'chunk' of text
(however formatted) on your page, they should be able to format the other
language equally.
- Offcourse, on a dynamic page, there a reason for it's dynamic, and you
have other database fields that have different translations, otherwise
you'd be better of including static html-files.
- I created a seperate table for system messages, like 'Login is
incorrect'.
- Determine which fields exactly have to be translated.
- create a table with possible languages, and possibly other info (money
formatting, dns, postal code formatting etc.)
- create a table translations with:
id id of row in specific table of which it is a translation
table table name of text to be translated
field field name of text to be translated
language language identifier
value translation (with or without HTML-markup, that doesn't matter)
Now, to build your page, first determine what language the user wants. I
use, in order of precedence:
- GET value (often obfuscated in an url, like
http:/example.com/nl/rest/of/path/to/file.php, which is parsed by
mod_rewrite on apache)
- cookie (on a GET value a cookie is set/changed offcourse)
- logged in users preference (on a change in preference offcourse a cookie
is set)
- HTTP header fo accepted languages (not always available for every
browser)
- when possible, trying to determine by referrer or remote adress suffix
what country, and possibly what language, the user prefers.
- is all else false, use default language
Now I set the constant LANGUAGE to preferred language.
On building the rest of the page, I can use queries with the set constant
LANGUAGE that the user prefers. For instance:
mysql_query'("SELECT
x.product_id AS id
IFNULL(y.value,x.name) AS name
IFNULL(z.value,x.desc) AS description
FROM products x
LEFT JOIN translations x
ON x.product_id = y.id
AND y.table = 'products'
AND y.field = 'name'
AND y.lang = '".LANGUAGE."'
LEFT JOIN translations z
ON x.product_id = z.id
AND z.table = 'products'
AND z.field = 'desc'
AND z.lang = '".LANGUAGE."'");
True, your queries are a bit longer, but in most servers the extra time
needed for the query is negligible.
You could even add your own logic to 'degrade' to some languages by
preference as indicated by the user (set a preference per available
language).
--
Grtz,
Rik Wasmus
[Back to original message]
|