I'm currently creating a multi-lingual website, and I have different types of words that are being translated all across the website. However, whats the best practice when it comes to storing this in the database?
This is what I currently do:
I have the language Norwegian and English.
My database looks like this:
Whenever I add a new language it get added into the languages table like this:
At the same time a new table will be created with looking like this language_en. Using the value in language_val.
Later on I use URL routing to retrieve en, no or whatever language and fetch the website information from the correct table.
My question is, should I rather have only 1 table and use the language_id in this one? or is it perfectly fine to split up languages into multiple tables?
Each language table would look just like this:
With Silverlight (and later with PHP) I've done this by putting the language's in the same table, this worked fine and was user friendly (easy to edit). Only when retrieving data you should off course only select the language you need.
Related
We're busy with a CakePHP project which needs to support multi languages. But there is one problem.... There are pages which are NOT supported for other languages. So there are Spanish pages which need to be hidden for the Italian version of the website. What is the better solution for this in CakePHP?
We can switch databases as soon as you switch languages, but the problem is that we will miss important data as users and such if we'll do that. And it may be overload to search a database with Spanish, Italian, German, English, Netherlands and Swedish posts, only for the Spanish posts. Or maybe it's not a problem if we index the language column... but I don't know.
So does anyone knows the better solution?
Definitely NOT multiple databases IMO. Instead, try to just keep your record separate from it's contents.
Example:
articles table contains non-language-specific data like article id, created date, modified date...etc
article_contents contains language-specific data like title, subtitle, content, authors...etc as well as an article_id field and a language field.
Then, if you're on the Italian site, you can pull with an INNER JOIN to the contents where it matches the language you want.
Or there are many ways depending on your setup on how you should pull data, but hopefully the idea for separation of generic data vs language-specific data helps.
instead of
echo 'Localization';
do
echo __('Localization');
http://book.cakephp.org/2.0/en/core-libraries/internationalization-and-localization.html
I need to create some sort of knowledge data base for updates (using PHP and MySQL).
Im using a database to store every update in HTML format.
People that are using the system work with different languages (information about users is stored in the DB).
Sometime the updates contain a text that should be translated and displayed taking into consideration the language that the user is working with.
What approach would you suggest, having in mind that i would like to avoid storing PHP and HTML in the DB.
I was thinking to create a col for every language and to store there the translation of every update, but what will happen it the update contains 2 different translations.
Prototype of the updates:
Some initial text
Translation of some part of the text
Some more text
Second translation
Final update text
I would create a table for languages and a table for updates. Then create a table that links languages to updates. One column for id, one column for language id, one column for update id. Then, you will be able to handle an update with multiple translations.
Another solution would be to use some sort of cdata tag, or something that you could parse easily enough. But this would be a very "wiki" based solution so there are patterns to follow to avoid mixing.
Example:
[English<-[This is the best update ever]->]
[Swedish<-[Detta är den bästa uppdateringen någonsin]->]
I've been struggling with this for a while now. One my CMS' is ready to be extended with a translation module. I've been thinking of different methods but haven't figured out what is the best way so far.
Basically I have a CMS which uses a template system to parse all data from a database to the screen. I've come so far to "split up" my templates in different folders to be able to translate things that are "static" like images with text, footer links, etc.
However, there are many modules (pages, news, products) that have multiple fields that require a database driven method to be translated. I started off with a "languages" table which describes languages (id, iso_code, name). That's as far as I've come.. since there were a couple of projects that had to be done I haven't spend any more time to this subject thus far.
My first thought ("the quick fix") was to add multiple fields inside the tables (such as "title_nl", "title_en"), but this actually makes the database more crowded than is needed in my opinion.
My second thought was to create a table, "news_translations" for example. Which contained the language iso code, a news_id, the fields that require translation. Obviously a news_id connects the translation to it's original and the language iso code is used to get the right language from the database. Then in my front-end code I would first check if the default language is selected (=> select from the "news" table) or a translation (=> check inside translations table). If the 2nd case does not return any results a message is display "Sorry, no translation available" and the default is shown (or an error message, what fits the client best..).
But then there's a 3rd option.. my websites all use search engine friendly links (www.domain.com/pagename/ or www.domain.com/news/1-news-item-here.html). It would be far better if I had the ability to also "override" the SEF URL in my translations table. But I guess in this case I would always need 1 extra query to the translations table (since we first want to check for a translated page)... guess it's not such a big deal, but it's worth considering I guess.
In the end I guess by describing my options number 3 is what I need. But I'd like to have some other opinions on the subject as well! This is what I am trying to achieve:
Create a CMS system with multi language support
No language files (obviously this is why I use templates)
Being able to translate an original page/newsitem/product
Optionally: to change the SEF URL according to the language
I think option 3 has all this.. so the steps to create this solution is:
Create a _translation table for each item (or perhaps even in the
original by adding 2 new fields 'translation_to' (containing the
PrimaryKey) and 'translation_is' (containing ISO code) - however..
in that case all fields would need to be edited (which is not always
necessary.. plus by creating a 2nd table I keep the originals
divided with their translations, right?)
If the default language is NOT chosen first query the translations table to find a translation, if one is found display the
translation. Otherwise notify/error the user and/or display the
original text (based on the SEF URL... if the SEF is not found
within the translations or original table, then obviously display an
error only).
Any suggestions? :-)
Thanks for thinking along!
I would like to see what your table structure looks like. Probably the best thing you can do is generate two seperate new tables named something like "CONTENT_MULTI_LANG" & "SITE_LOCALES".
Then in the code that prints out your content do an initial check for a language flag. I'd create two separate classes for loading static content, something like "Content_LoadStandard" and "Content_LoadMultiLang". So then your conditional will look like this.
if ($this->site_locale == 'standard'){
$contentLoader = new Content_LoadStandard();
} else {
$contentLoader = new Content_LoadMultiLang($this->site_locale);
}
$content->blah($cheese);
Your "CONTENT_MULTI_LANG" table should be a narrowed down version of your standard CMS object table, only containing the relevant content field(s) that need to be in alternative languages.
// PSEUDO SQL
CREATE TABLE `LOCALE` (
`id` int(11),
`locale` varchar(16), // name of locale (language)
... // any other fields
)
CREATE TABLE `CONTENT_MULTI_LANG` (
`id` int(11),
`pcid` int(11), // parent content id
`lid` medint(), // locale id
`content` {$type}, // whatever type you use (varchar, text, bin, etc)
... // any other fields
)
In your Content_LoadMultiLang class, create methods to query alternate content using a join.
TIP: Might be a good idea to establish relationships in your table to do cascading deletes on content rows, that way if you delete content in standard your multi lingual version(s) will also be deleted.
From what I've seen from Drupal, option three is how they handle it, with a couple of tweaks. They keep it all in one table and a field called language. Then there is a separate table that maps which items are connected.
This way is primary language agnostic, meaning the content can be created in any language without requiring a translation in any other.
I am currently making a web page with dynamic content from a database (a restaurant menu) storing item names, prices, yada yada. The restaurant usually caters to English and Japanese. I have stored the titles of the items in the database as English and Japanese, however when it comes to the type of the item, for example, Type: Drink, Type of Drink: Coffee I can obviously store the type of item alongside the item in the database, but it hardly seems worth it to store it twice as two different languages in the the database which would also make the form to add a new item a pain.
What is the best way to go about translating those little tiny pieces of information, like "Coffee", "Wine", "Click Here", "Menus", and using them on the page?
You can use gettext extension for translation static or predefined info on web page.
See manual http://php.net/manual/en/book.gettext.php
Example http://mel.melaxis.com/devblog/2005/08/06/localizing-php-web-sites-using-gettext/
I would store it in both languages, it makes the most sense to me. I don't see why you would go and do a request to your translation system each time you want to show any page in your menu.
If you are using an automatic translation system that you really trust, one thing that you could do is use it when adding a new item to make a suggestion. So, after the user enters the word in English on the form, automatically attempt to translate that into Japanese and put it in the Japanese field. If the user is satisfied with the translation, that's it for that task, otherwise he/she inputs with a better one.
if you are using any phph5 based framework , major framework have localization support like zend has Zend_Locale
if you want your own translation dictionary , keep key value pair data in database table and memcached between application and DB , so static data will be cached for particular expiry time and data base load will be get decreased and fast retrieval of data
So I need to make a site available in different languages. Using PHP 5.x and MySQL 5.x. I believe I will be using gettext which seems fine for static text throughout the site but what about dynamic data that is stored in the db? Im referring to things like stories, events business listings etc. How do I get those to display in a different language? My initial thought was in the backend have them be able to enter multiple versions of a story, event or listing, one for each language they want to use on the site. But there could be thousands of entries times how many languages they want to show. Is there a better solution/idea that someone can point me to?
Also another issue I was thinking is currently the site allows you to search events/stories/listings, how would that work in different languages? Im assuming if someone selected the site to show in spanish they are going to use spanish words to search the site, but if the information in the db is in english I dont know that would work. Any suggestions on that?
If you want the stories to be correct in all languages, then you need them stored in all languages and provide the backend to do the translations or enter the stories on different languages as you initially thought.
If you don't like that, you might add the google translate element in your pages, to provide automatic (not correct) translation.
For the search question, I would only search for the keywords in the fields of the database in the same language as the user. If Joe is visiting your page in English, only look for the search terms in title_en, content_en, description_en fields of your database (or the ones with language='en' if you have one row per article and translation in the database, instead of one row per article (with all translations inside)). Obviously, this does only work if you put all the translations on the database.
The best solution I have seen described is this.
As i18n CMS sites as you describe are in a constant state of flux, with new articles being added, some of which have had translations, in some languages.
If an article in a chosen language has not yet been translated then show a default language (English?).
Then pick any ideas which appeal to your case:
a) If showing a default article in English also throw onto the page an input box and invite your audience to translate it for you.
b) If showing a default article in English also put on the page an offer to send the content to google translate as well as doing a) above
c) put a bounty on the translation and optionaly do a) and/or b) above.