I'm currently having some issues with multi lingual templates.
Our project has two languages; nl-NL and en-US. In the email template section, there are options for 'common' and both languages.
Whatever I do, the 'Common' is always chosen, and not the language specific one. The Common sends the email, no problems, but it is obviously not always the correct language.
Remark: My order does not have any languageId, and when I try to set it in code, I get the following exception:
Type: Error | User: 0 | NodeId: -1 |
Comment: Error sending email using the email template: Confirmation email email for order {someguidhere} -
Exception: System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
at System.String.Format(IFormatProvider provider, String format, Object[] args)
Be sure to have the latest Tea Commerce 2.x installed - I know that there was some problems with getting the language id in older versions of 2.x.
Try hook into the NotificationCenter.EmailTemplate.ErrorSendingMail event handler - there you get the exception and can see more details. I cant see where in TC we use a string.format in the email sending. Maybe there is an error in the razor file that you use to render the email?
I'm using the default template, and I'm running the latest TeaCommerce. I'll try to hook into the ErrorSendingMail to see if I get more specific errors.
The language id is an id of an Umbraco language. So be sure to set it to a language id that exists in Umbraco. Maybe that is the error :)
When Tea Commerce creates an order. It will use the product identifier (nodeId) to loop ancestor or self to see if any has a hostname associated with it and then see the language of the hostname. If it find a language id it will add it to the order.
The language IDs (1 and 2) are present in Umbraco.
I'm using a product catalog, so the products do not descend from the nodes; see this example:
As you can see, the products do not have a parent with a language. I'm using content pages, with 'product pickers' in them to enable the same product being used within all languages.
Could this be part of the problem, and better yet, is there an solution?
Duplication of products is a bit of an anti-pattern, so I would like to continue to use this setup.
The way we normally do multi language setup is using the master relation feature in Tea Commerce. Try and download the starter kit and see how its done with a product catalog and then a "copy" of the product at every language.
You dont see line numer in the error or a stacktrace or something like that?
This could present some problems, because not all products are available in all languages. If someone puts an item from the NL shop in the basket, and proceeds to EN, and adds another product, what will happen?
The language id is updated everytime an order line is added. So the last order line that is added defines the language. And the email will use that id to find the hostname/culture and use that culture for the rendering of the email.
If the EN and NL product has the same SKU, then the order line will now have a quantity of two but still use the name (NL) and properties that was copied when the order line was first added.
I've resolved the issue by adding more logic to the email template. By setting the culture depending on the 'Model.PaymentInformation.CountryId', I have a more reliable source for my choice of language.
After that, I can simply call the Umbraco Dictionary so I can reuse all my entries. Works like a charm, and we don't have to implement multiple templates.
Thanks for your quick replies and have a great weekend!
Great to hear you found a way to solve you problem. Can you post some of the solution so others can benefit from the support here at the forum? And then mark that answer as the solution to the post?
In this example I set the culture to nl-NL on countries with ID 2 and 3, and to en-US on all other country IDs. You should offcourse determine for yourself which IDs should map to which culture, it is up to you. Our site has only two languages, so this setup was enough.
Because of the use of these culture settings, just add all labels to the dictionary, and place them in the code like normal:
EmailTemplate and multiple languages
I'm currently having some issues with multi lingual templates.
Our project has two languages; nl-NL and en-US.
In the email template section, there are options for 'common' and both languages.
Whatever I do, the 'Common' is always chosen, and not the language specific one.
The Common sends the email, no problems, but it is obviously not always the correct language.
Remark: My order does not have any languageId, and when I try to set it in code, I get the following exception:
Any ideas anyone?
Kind regards,
Peter Rombouts
Be sure to have the latest Tea Commerce 2.x installed - I know that there was some problems with getting the language id in older versions of 2.x.
Try hook into the NotificationCenter.EmailTemplate.ErrorSendingMail event handler - there you get the exception and can see more details. I cant see where in TC we use a string.format in the email sending. Maybe there is an error in the razor file that you use to render the email?
Kind regards
Anders
Hi Anders,
I'm using the default template, and I'm running the latest TeaCommerce.
I'll try to hook into the ErrorSendingMail to see if I get more specific errors.
Will post my results, thanks for the reply!
Kind regards,
Peter Rombouts
I've hooked into the error, and all I got was:
Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
Can you explain what the mailtemplate does?
Or better; can you explain how to set another language?
Is the 'languageId' on Order some kind of dependency (because it is empty, as it is not an required field).
Kind regards,
Peter Rombouts
The language id is an id of an Umbraco language. So be sure to set it to a language id that exists in Umbraco. Maybe that is the error :)
When Tea Commerce creates an order. It will use the product identifier (nodeId) to loop ancestor or self to see if any has a hostname associated with it and then see the language of the hostname. If it find a language id it will add it to the order.
Kind regards
Anders
Hi Anders,
The language IDs (1 and 2) are present in Umbraco.
I'm using a product catalog, so the products do not descend from the nodes; see this example:
As you can see, the products do not have a parent with a language.
I'm using content pages, with 'product pickers' in them to enable the same product being used within all languages.
Could this be part of the problem, and better yet, is there an solution?
Duplication of products is a bit of an anti-pattern, so I would like to continue to use this setup.
Kind regards,
Peter Rombouts
The way we normally do multi language setup is using the master relation feature in Tea Commerce. Try and download the starter kit and see how its done with a product catalog and then a "copy" of the product at every language.
You dont see line numer in the error or a stacktrace or something like that?
Kind regards
Anders
Hi Anders,
This could present some problems, because not all products are available in all languages.
If someone puts an item from the NL shop in the basket, and proceeds to EN, and adds another product, what will happen?
What language will be chosen for the email?
Kind regards,
Peter Rombouts
The language id is updated everytime an order line is added. So the last order line that is added defines the language. And the email will use that id to find the hostname/culture and use that culture for the rendering of the email.
If the EN and NL product has the same SKU, then the order line will now have a quantity of two but still use the name (NL) and properties that was copied when the order line was first added.
Kind regards
Anders
Hi Anders,
I've resolved the issue by adding more logic to the email template.
By setting the culture depending on the 'Model.PaymentInformation.CountryId', I have a more reliable source for my choice of language.
After that, I can simply call the Umbraco Dictionary so I can reuse all my entries.
Works like a charm, and we don't have to implement multiple templates.
Thanks for your quick replies and have a great weekend!
Kind regards,
Peter Rombouts
Great to hear you found a way to solve you problem. Can you post some of the solution so others can benefit from the support here at the forum? And then mark that answer as the solution to the post?
Kind regards
Anders
The fix I provided works as following:
Edit the email-template-confirmation.cshtml file, and add the following code at the start of the file:
In this example I set the culture to nl-NL on countries with ID 2 and 3, and to en-US on all other country IDs.
You should offcourse determine for yourself which IDs should map to which culture, it is up to you.
Our site has only two languages, so this setup was enough.
Because of the use of these culture settings, just add all labels to the dictionary, and place them in the code like normal:
This solution will enable you to have only one template, and re-use dictionary items within the shop, Umbraco pages, and your email template.
Kind regards,
Peter Rombouts
is working on a reply...