问题
I need comments on my solution of a website localization system.
Table Content:
Field Type Null Key Default Extra
id int(11) NO PRI NULL auto_increment
Page varchar(30) YES NULL
Locale varchar(10) YES NULL
Data longtext YES NULL
My thought is to store each page and each locale into the Content table. For example:
index.php en_GB {data}
index.php de_DE {data}
The Data field would consist of a json_encoded array in which the text of each of the page elements would be stored. For example:
$data['Headline1'] = 'The Headline';
$data['Welcome'] = 'The welcome text.';
I have yet to implement it, but I plan on using memcached to improve performance - and from the little I know this is the perfect kind of data to use it on since it is not prone to be updated very often.
Is this good or bad, should it all be scrapped? Comments please!
回答1:
Some notes:
- Don't store translations per page, this would cause alot of redundant data as some translations will occur om multiple pages.
- I advice against throwing all translations into one field in the database, add an entry for each translated sentence.
- Replace locale (varchar) with an unsigned tinyint and create an index on it, please the locales in an locale table.
Something along the likes of:
translationId | localeId | translationKey | translationText
回答2:
If you want to do localization in PHP use gettext and you will have time do implement other features too, instead of building your own localization system.
Do not worry about speed, php gettext extension runs faster than using strings arrays.
来源:https://stackoverflow.com/questions/6303857/language-localization-in-php