DotCMS Multilingual Approach

317 views
Skip to first unread message

Alex

unread,
Jun 4, 2012, 7:52:49 AM6/4/12
to dot...@googlegroups.com
Hi,

I am working on translating our site in Spanish. Some structures have
categories and custom fields.

a. Do I need to create a new set of Spanish categories and then add
them a new field to the structure?
b. Do I need to create a new role for a Spanish User and permission
the Spanish categories so that the Spanish user is the only one who
sees them?

As far as custom fields? How do I pull items from two different hosts
in different languages?

$dotcontent.pull("+structureName:structureName +(conhost:myHostID
conhost:SYSTEM_HOST))

Adding another +(conhost:myOtherHostID conhost:SYSTEM_HOST) does not
seem to work.

And, what is the variable of the language that I need to pull?


Also, do I need to create a relationship so dotCMS "knows" which
content item is the translation of the original in English?


Thanks,

Alex





Maria Ahues Bouza

unread,
Jun 4, 2012, 11:57:47 AM6/4/12
to dot...@googlegroups.com
Alex,

For the categories you can either create two sets of categories and on
your widgets check the language and use the appropriate category or
create one set of categories and for the category names use language
keys, keys that are included in the Language Manager, and then when
displaying the category on your widgets you use
$get.text($category.name)

If you use two sets of categories I think it's a good idea to
permission them differently so users can only see their own
categories.

On your lucene queries you will need to use +languageId:1 (passing the
language id).

You can use the language_id variable from the request to send to the query.

I don't understand the question about the hosts in the query, you want
to do another OR? If so just add it like this

$dotcontent.pull("+structureName:structureName +(conhost:myHostID
conhost:SYSTEM_HOST conhost:myOtherHostID ))

-Maria
> --
> You received this message because you are subscribed to the Google Groups
> "dotCMS User Group" group.
> To post to this group, send email to dot...@googlegroups.com.
> To unsubscribe from this group, send email to
> dotcms+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/dotcms?hl=en.
>



--
Community Manager

dotCMS
Main: 305.900.2001
Fax: 305.397.2579
www.dotcms.com
http://www.twitter.com/dotCMS
http://www.facebook.com/dotCMS
http://www.twitter.com/mabouza

Please consider the planet before printing this email.

Alex

unread,
Jun 4, 2012, 4:41:36 PM6/4/12
to dot...@googlegroups.com
Thanks Maria!

For the pull, I want to pull all items in Spanish and English from two
different hosts. So I am doing:

+structureName:structureName +(conhost:HOSTID1 conhost:HOSTID2
conhost:SYSTEM_HOST) +languageId:1 +languageId:2

The above does not pull anything.


Alex

Maria Ahues Bouza

unread,
Jun 4, 2012, 5:01:25 PM6/4/12
to dot...@googlegroups.com
Alex,

What you're doing there is doing an AND with the two languages. You
need to do an OR.

+structureName:structureName +(conhost:HOSTID1 conhost:HOSTID2
conhost:SYSTEM_HOST) +(languageId:1 languageId:2)

and also on a given language you can only display the current
language's content.

If you are seeing the page in spanish only the content in spanish will
be available on that page.

-Maria

Alex

unread,
Jun 4, 2012, 5:06:46 PM6/4/12
to dot...@googlegroups.com
What I have is a custom field that pulls out all the items on a
structure and displays them on a drop down field.

The code you suggested only pulled the Spanish items of the
structure. My settings are in English.

Alex

Maria Ahues Bouza

unread,
Jun 4, 2012, 5:26:35 PM6/4/12
to dot...@googlegroups.com
What do you mean your settings are in English.

If you look at the page in Spanish you will only get the content in
Spanish no matter what you put on the query.

If you look at the page in English you will only get the content in English.

Alex

unread,
Jun 4, 2012, 5:30:37 PM6/4/12
to dot...@googlegroups.com
I am looking at the custom field drop down field in the back end in
the content item with the English Language set and on the pull I only
see the items pulled in Spanish.

Maria Ahues Bouza

unread,
Jun 4, 2012, 6:10:42 PM6/4/12
to dot...@googlegroups.com
Can you do your example in demo so i can take a look at it and see what's wrong?

That would be easier to test.

Alex

unread,
Jun 4, 2012, 8:16:59 PM6/4/12
to dot...@googlegroups.com
ok, I went in the demo.

I created a structure called: BlogName

I added a custom field called Blog Name that does the pull from
BlogName in English and Spanish as per your instruction in the blog
structure of the demo site.

You can try to create a blog now and you will see that the first drop
down field only display items in Spanish. It does not display the
content items of BlogName structure in English.

Maria Ahues Bouza

unread,
Jun 4, 2012, 8:35:23 PM6/4/12
to dot...@googlegroups.com
Ok on the query it had +language_id:2 I changed to be: language_id:2
and it works.

But now it shows both english and spanish and I think you'd want it
based on the language session right?
>>>>>>>> $dotcontent.pull("+structureName:structureName +(conhost:myHostID
>>>>>>>> conhost:SYSTEM_HOST conhost:myOtherHostID ))
>>>>>>>>
>>>>>>>> -Maria
>>>>>>>>
>>>>>>>> On Mon, Jun 4, 2012 at 4:52 AM, Alex <alex.t...@ambix.net>
>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> I am working on translating our site in Spanish.  Some structures
>>>>>>>>> have
>>>>>>>>> categories and custom fields.
>>>>>>>>>
>>>>>>>>> a. Do I need to create a new set of Spanish categories and then add
>>>>>>>>> them
>>>>>>>>> a
>>>>>>>>> new field to the structure?
>>>>>>>>> b. Do I need to create a new role for a Spanish User and permission
>>>>>>>>> the
>>>>>>>>> Spanish categories so that the Spanish user is the only one who
>>>>>>>>> sees
>>>>>>>>> them?
>>>>>>>>>
>>>>>>>>> As far as custom fields?  How do I pull items from two different
>>>>>>>>> hosts
>>>>>>>>> in
>>>>>>>>> different languages?
>>>>>>>>>
>>>>>>>>> $dotcontent.pull("+structureName:structureName +(conhost:myHostID

Maria Ahues Bouza

unread,
Jun 4, 2012, 8:38:21 PM6/4/12
to dot...@googlegroups.com
I changed it on demo to use the language from the URL.

This is what I changed on the code


#set($languageId = $request.getParameter("lang"))

#foreach($con in $dotcontent.pull("+structureName:BlogName +(conhost:d234cfc0-926e-49d1-a7a8-d7033ffe793f conhost:48190c8c-42c4-46af-8d1a-0cd5db894797 conhost:SYSTEM_HOST) +languageId:$languageId",0,"BlogName.name asc"))

Alex

unread,
Jun 4, 2012, 8:44:18 PM6/4/12
to dot...@googlegroups.com
Thank YOU! It is fine if it shows both.

However, it would be nice to be based on the language session.

Alex

Alex

unread,
Jun 4, 2012, 8:47:09 PM6/4/12
to dot...@googlegroups.com
It works like a charm!!! Thank YOU!
Message has been deleted

Alex

unread,
Jul 31, 2012, 12:56:33 PM7/31/12
to dot...@googlegroups.com
Hi, Maria:

I do appreciate all the time, dedication and love you take when you answer questions in the mailing list.  I have been playing with the multilingual features for a couple of months and tested with some users.  I have come to the conclusion that the best approach to multilingual is to create a specific host for the language since the multilingual features are still buggy (URLContentMap and templates don't use the default language when there is nothing in Spanish.)  For example, if I set my language to Spanish and I go to a page that is not in Spanish dotCMS shows a blank page instead of the default language English.  So this does not help to the use experience.

I think it is best to set one host with the es.mysite.com to be in the foreign language using the same URLContentMaps set on dotCMS and pulling only one language.  It will make things easier to manage.  The variable ?language=1 works great if you are doing a full translation of your site, otherwise, it does not work well when you want to translate specific areas of the site only.  Also, Google does not recommend using a URL language parameters ?lang: http://support.google.com/webmasters/bin/answer.py?hl=en&answer=182192.

I hope the above process will help others who will go through the same thing. :)

Now, I have a question for you.  On your blog: http://dotcms.com/blog/post/implementing-multilingual-sites-using-dotcms/

You stated:

  • If you want your website to have one host per language like this:

es.mysite.com
en.mysite.com
fr.mysite.com

You need to create one host: www.mysite.com and create all other hosts as aliases.

Does the above still apply to 2.1?  I was thinking just creating a new host called es.mysite.com and deploy everything there.  If I do an alias as you are suggesting how do I set it so that it shows the root folder I want?

Thanks,

Alex

Maria Ahues Bouza

unread,
Aug 1, 2012, 6:48:52 PM8/1/12
to dot...@googlegroups.com
Alex,

Thanks for your feedback :)

About creating a new host for your multilingual site, it's definitely an option but not the easiest to maintain. The way dotCMS was built is to create only one host and easily translate between both languages by just switching the language id. This allows you to maintain only one site instead of multiple ones.

The only reason where I would maintain separate hosts would be if the folder and page structures are different, and in that case they really are different websites.

If the sites are the same and only the content, labels, images are different in different languages then you should create only one host.

My comment in the blog about the other urls, like es.mysite.com is if you have two sites: en.mysite.com and es.mysite.com you can have them both as aliases on your default host, that way you can access your same site using either URL. Still this approach is using only one host.

If there are bugs in how this works we'd like to know, please feel free to submit them in Github.

You mention two bugs here:

1. URLContentMap and templates don't use the default language when there is nothing in Spanish. This should be reported in Github

2. If I set my language to Spanish and I go to a page that is not in Spanish dotCMS shows a blank page instead of the default language English. I don't understand this issue because a page is not language specific, only the content, so a page will always exist in both languages even if you don't have language specific content for it.

Thanks
Maria

Alex

unread,
Aug 2, 2012, 9:46:37 AM8/2/12
to dot...@googlegroups.com
Thank you for your advise!  I do see the point of having just one host specially when you have a mobile site and a standard site so I will be maintaing like 4 sites if I do the different host.

I reported the issue and you created an entry in Github:


The second issue is like this:

I have set up only a few sections of my site in Spanish.  

If the user goes to:


and then clicks on a link that goes to the English area, he gets the page empty (template with English containers) with no widgets, instead of the version in English.  I understood that dotCMS would display the default language (English) if there is nothing set up in Spanish.  Is this correct? 

I tried to add the language variable to each link on the containers, but then I realized it would mean recreate all the widgets in Spanish and add language variables and that would be like redoing the whole site.

Do you have a suggestion on how to handle the above?  I just need a few sections of my site in a foreign language and I don't want to redo the whole site.


On the backend, if I start switching from Spanish to English there is a point where all the custom field stop working - even if they have the language variable set.  So to fix this, I just had to add the language variable to English and it seems to work.


Alex

Maria Ahues Bouza

unread,
Aug 2, 2012, 4:49:42 PM8/2/12
to dot...@googlegroups.com
Alex,

You have two different folders for english and spanish?

/es/ and /en/?

dotCMS uses the default language only if you set it in the dotmarketing-config.properties.

You need to search for these variables:

DEFAULT_LANGUAGE_COUNTRY = United States
DEFAULT_LANGUAGE = en_US
DEFAULT_LANGUAGE_CODE = en
DEFAULT_LANGUAGE_STR = English
DEFAULT_LANGUAGE_COUNTRY_CODE = US
DEFAULT_CONTENT_TO_DEFAULT_LANGUAGE=true

-Maria

Alex

unread,
Aug 2, 2012, 10:24:54 PM8/2/12
to dot...@googlegroups.com
Maria:

I did not have this variable:

DEFAULT_CONTENT_TO_DEFAULT_LANGUAGE=true

I am going to include it and test.  I think this will solve the main problem. :)

I only have 1 or 2 folders that are bilingual, the rest are in English.

Thank You!

Alex

Maria Ahues Bouza

unread,
Aug 3, 2012, 12:42:52 PM8/3/12
to dot...@googlegroups.com
Yes that variable is what you need to make sure it defaults to English.

Alex

unread,
Aug 6, 2012, 10:09:08 PM8/6/12
to dot...@googlegroups.com
Maria:

Here is another bug I found:


It makes the backend impossible to do relationships in a foreign language.  Is there a way around this?

Alex

Maria Ahues Bouza

unread,
Aug 6, 2012, 10:54:21 PM8/6/12
to dot...@googlegroups.com
You're right I just tested in demo and I can reproduce the issue.

The only work around I can see is to create a dummy placeholder version in English of your same Spanish content, that way it will show up in the Relationship search. You can relate the Spanish one to the English one because they are both under the same identifier, so relating one will relate both. 

Alex

unread,
Aug 6, 2012, 11:02:48 PM8/6/12
to dot...@googlegroups.com
Maria:

I added a new bug. ;-) 

I am sorry I don't understand.

The content item in Spanish has the same identifier as that of the English one?
How does dotCMS determines this?  I mean how does it know that one content item is the translation of the other one?

The way I am inputting the content items is first I do the batch in Spanish and then I do the batch in English.  Is there a specific way I need to create them so that hte identifiers are the same?


Alex

Maria Ahues Bouza

unread,
Aug 6, 2012, 11:19:35 PM8/6/12
to dot...@googlegroups.com
Alex,

Yes they both have the same identifier, and each one has its own inode. One identifier has at least one working / live version of each language. 

That's how dotCMS knows that both content translations are the same piece of content translated. 

Oh the way you're doing it, you're creating two separate identifiers. If you open one of your Spanish pieces of content and change the language you won't see the English version right? Because they are two completely pieces of content.

The way it should work is to have a piece of content created in Spanish for instance and then edit it and change the language to English and add the content there. That way they are both under the same identifier and dotCMS knows to translate them. Also this allows you to only have to add the content to a page once, and dotCMS takes care of showing the correct content based on language.

If you are doing a batch upload, you can import the file in both languages at the same time. When you import content it has a drop down for language, you can choose multilingual file. You will need to add two columns on your file languageCode and countryCode on each record, also you'll need a key so dotCMS knows which two are the same content.

-Maria 

Alex

unread,
Aug 6, 2012, 11:24:41 PM8/6/12
to dot...@googlegroups.com
Maria:

What key can I choose so dotCMS knows two items are the same?  The title is different in Spanish

Thank you so much!

Alex

Maria Ahues Bouza

unread,
Aug 6, 2012, 11:34:36 PM8/6/12
to dot...@googlegroups.com
Do you have any field that you can use as a key?

If not maybe you can create one just for the importing to work?

Alex

unread,
Aug 6, 2012, 11:39:36 PM8/6/12
to dot...@googlegroups.com
Thank you!  I will create a field for importing and matching the two content items.

Alex

unread,
Aug 7, 2012, 12:29:03 AM8/7/12
to dot...@googlegroups.com
When I do the multilingual batch import I selected a key, then  it imported all the content items and assign them to the specific languages, but with different identifiers, even if the keys matched. 

Any other suggestions?

Alex

Maria Ahues Bouza

unread,
Aug 7, 2012, 11:23:36 PM8/7/12
to dot...@googlegroups.com
Alex,

I tried importing using languageCode and countryCode and got this error

Warnings:

  • Header: "languageCode" doesn't match any structure field, this column of data will be ignored.
  • Header: "countryCode" doesn't match any structure field, this column of data will be ignored.
Did you not get this error?

I submitted the bug in Github:

What probably happened to you is all the content got imported as English?


-Maria

Alex

unread,
Aug 7, 2012, 11:22:31 PM8/7/12
to dot...@googlegroups.com
You need to select Multiple Language File and you will not get that error.

I tried importing content item in both languages and I never get them to match the identifiers. :(  Maybe it is a bug?

Alex

Alex

unread,
Aug 7, 2012, 11:24:12 PM8/7/12
to dot...@googlegroups.com
All content is imported in its appropriate language.  The problem is that the content item in English does not match the identifier of the content item in Spanish.

Maria Ahues Bouza

unread,
Aug 7, 2012, 11:38:48 PM8/7/12
to dot...@googlegroups.com
It's obviously late because I thought I had clicked on it ;)

Ok so that worked. 

But the content was created separately.

This is how I was able to make it work.

1. Create the content in English first. This is my file in English.
Key,Title
K1,Title 1
K2,Title 2
K3,Title 3

2. Export the content in the Content Search page. This is what I had on my exported file
Identifier,languageCode,countryCode,Key,Title
f9ce2dcd-e032-46eb-89c3-f20ab4df1dc0,en,US,K3,Title 3
71f6db4d-11a4-4555-85ed-291fad45811f,en,US,K1,Title 1
3c98d143-1a47-4f3c-9d38-b9edfb3e9197,en,US,K2,Title 2


3. Use the identifier field in the import file to import in Spanish. This is my file in Spanish
Identifier,languageCode,countryCode,Key,Title
f9ce2dcd-e032-46eb-89c3-f20ab4df1dc0,es,ES,K3,Titulo 3
71f6db4d-11a4-4555-85ed-291fad45811f,es,ES,K1,Titulo 1
3c98d143-1a47-4f3c-9d38-b9edfb3e9197,es,ES,K2,Titulo 2

Alex

unread,
Aug 7, 2012, 11:43:49 PM8/7/12
to dot...@googlegroups.com
Thank you Maria!  That worked!
Reply all
Reply to author
Forward
0 new messages