dropdown multiple: translating and comma separator
So, I'm trying to make a multi-lingual site, and have come acrosse an issue I can't solve. In this site I have a custom datatype rendered by a "Dropdown list multiple". This holds a list of strings, some of them with commas, like this example: "red, or blue".
I then show in the frontpage which values a document has, so it can be:
Colors in this document: white, yellow, red, or blue
As you can see, the values are separated by comma, which is not that good since some of the values have "inner" commas. The main question is how can we make this "translateable"? That is, how can we show this page with translated values?
A secondary question is how can we separate the values with something other than commas?
been looking into this some more. It seems the data is saved in xml as a string of values separated by commas. That's why we get this string in the frontoffice...
So I guess to get the individual list items correctly we have to go to the database get the ids of the values? And then get the values themselves... concatenate a string with the chosen separator. And translate what we want in the process...
Jan, the problem with this approach is it doesn't work when your individual values include commas themselves. Take for instance, the example of a category: "Agriculture, Animal Farming, and Fishing". This would be a single option:
<value>Services</value> <value>
Agriculture, Animal Farming, and Fishing
</value> <value>Education</value>
Using Split would give wrong results, indicating 5 values instead of just 3.
But would'nt that be a matter of checking if the <value> element contains ',' - and if it does then split it again? Or do I misunderstand the issue totally? :-)
That can't be. You want to consider a single value as just that, even if it contains commas. Picture a value that is in fact a small phrase. You want to translate the phrase, not word by word. In my example I have a single value that is "Agriculture, Animal Farming, and Fishing". I don't want to split this into 3 values, and then translate each one separatly - that would be a nightmare. Also, when presenting this single value to the user I don't want it splitted.
So in the code above, the foreach cycle would produce 3 sValues:
Services Agriculture, Animal Farming, and Fishing Education
Each of these can be translated, to for example french:
Service Agriculture, Élevage, et de la Pêche Éducation
If you separated the 2nd item, you would make your translators translate bits and pieces of expressions, and hope they all glue together fine...
dropdown multiple: translating and comma separator
So, I'm trying to make a multi-lingual site, and have come acrosse an issue I can't solve. In this site I have a custom datatype rendered by a "Dropdown list multiple". This holds a list of strings, some of them with commas, like this example: "red, or blue".
I then show in the frontpage which values a document has, so it can be:
Colors in this document:
white, yellow, red, or blue
As you can see, the values are separated by comma, which is not that good since some of the values have "inner" commas. The main question is how can we make this "translateable"? That is, how can we show this page with translated values?
A secondary question is how can we separate the values with something other than commas?
Thanks,
Duarte
been looking into this some more. It seems the data is saved in xml as a string of values separated by commas. That's why we get this string in the frontoffice...
So I guess to get the individual list items correctly we have to go to the database get the ids of the values? And then get the values themselves... concatenate a string with the chosen separator. And translate what we want in the process...
whew... any tips? code to share?
Duarte
Hi Duarte
If you use XSLT to fetch the values you can make use of the umbraco.library:Split() extension where you can split by comma like this.
<xsl:variable name="values" select="umbraco.library:Split($currentPage/yourpropertyname,',')" />
This gives you some XML that should look like this (from the top of my head)
<values>
<value>red</value>
<value>blue</value>
<value>white</value>
</values>
Then you should be able to loop through the values like this...
<xsl:for-each select="$values//value">
<xsl:choose>
<xsl:when test="position() = last()"> or <xsl:value-of select="." /></xsl:when>
<xsl:otherwise><xsl:value-of select="." />,</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
This should give you the result you're after - does it work for you?
Is this what you're after?
Jan, the problem with this approach is it doesn't work when your individual values include commas themselves. Take for instance, the example of a category: "Agriculture, Animal Farming, and Fishing". This would be a single option:
<value>Services</value>
<value>
Agriculture, Animal Farming, and Fishing
</value>
<value>Education</value>
Using Split would give wrong results, indicating 5 values instead of just 3.
Duarte
What I have now:
But this would all be easy to solve by setting a different separator in lists... or storing the ids of the values in the xml.
Duarte
Hi Duarte
But would'nt that be a matter of checking if the <value> element contains ',' - and if it does then split it again? Or do I misunderstand the issue totally? :-)
/Jan
That can't be. You want to consider a single value as just that, even if it contains commas. Picture a value that is in fact a small phrase. You want to translate the phrase, not word by word. In my example I have a single value that is "Agriculture, Animal Farming, and Fishing". I don't want to split this into 3 values, and then translate each one separatly - that would be a nightmare. Also, when presenting this single value to the user I don't want it splitted.
So in the code above, the foreach cycle would produce 3 sValues:
Services
Agriculture, Animal Farming, and Fishing
Education
Each of these can be translated, to for example french:
Service
Agriculture, Élevage, et de la Pêche
Éducation
If you separated the 2nd item, you would make your translators translate bits and pieces of expressions, and hope they all glue together fine...
Duarte
is working on a reply...