Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Duarte Carreira 47 posts 66 karma points
    Apr 30, 2011 @ 17:13
    Duarte Carreira
    0

    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

     

  • Duarte Carreira 47 posts 66 karma points
    May 02, 2011 @ 16:58
    Duarte Carreira
    0

    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

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    May 03, 2011 @ 07:24
    Jan Skovgaard
    0

    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?

  • Duarte Carreira 47 posts 66 karma points
    May 03, 2011 @ 14:08
    Duarte Carreira
    0

    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

  • Duarte Carreira 47 posts 66 karma points
    May 03, 2011 @ 17:20
    Duarte Carreira
    0

    What I have now:

    oDocument = new Document(Convert.ToInt32(nodeId));
    documentProperty = oDocument.getProperty(attrName);
    tipoValor = documentProperty.PropertyType.DataTypeDefinition.DataType.DataTypeName;
    idsValues = documentProperty.Value.ToString();
    if (tipoValor.ToLower().Contains("dropdown list") || tipoValor.ToLower().Contains("checkbox list"))
    {
      foreach (string sValId in idsValues.Split(','))
      {
        int idVal = int.Parse(sValId);
        string sValue = umbraco.library.GetPreValueAsString(idVal);
        string sTradVal = umbraco.library.GetDictionaryItem(sValue);
        result += sTradVal + ";"
      }
      result = result.TrimEnd(';');
    }

    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

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    May 03, 2011 @ 22:47
    Jan Skovgaard
    0

    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

  • Duarte Carreira 47 posts 66 karma points
    May 03, 2011 @ 23:49
    Duarte Carreira
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft