<apex:outputText> accepts an arbitrary number of nested param tags, which is useful for inserting values in Custom Label translations.

Unfortunately there's a bug: if there's an apostrophe character in a translation it will prevent the substitution of values after the apostrophe. This can be circumvented by doubling the apostrophe (How to programmatically double apostrophes in custom label translations?), but using this wouldn't be DRY.

Is it possible to "extend" the outputText component so that inside a custom component the apostrophe doubling could be done automatically?

I'm looking for implementing something like this:

<c:translate label="{!$Label.myLabel}">
  <apex:param value="{!firstParam}"/>
  <apex:param value="{!secondParam}"/>

I haven't been able to figure out yet how to access these parameters from the custom component's controller class.

Essentially this is what I'd like to shorten:

<apex:outputText value="{!SUBSTITUTE($Label.myLabel, $Label.SingleQuote, $Label.SingleQuote & $Label.SingleQuote)}">
  <apex:param value="{!firstParam}"/>
  <apex:param value="{!secondParam}"/>

Update: I'd like to emphasize that I want to accept any number of parameters for this component, as there can be no limit as to how many placeholders will the string contain which I need to translate.

  • Mostly just glad I found the double-quote workaround. Thanks for this! – psheil Sep 14 '16 at 23:30

I think what you want is for your component to just be:

    <apex:attribute type="String" name="label" description="Label to output" />
    <apex:variable var="singlequote" value="{!$Label.SingleQuote}" />
    <apex:outputText value="{!SUBSTITUTE(text, singlequote, singlequote & singlequote)}">

Then in your page, you just do:

<c:translate label="{!$Label.myLabel}" / >

No inner params necessary.

  • How would I pass an arbitrary number of values to the Custom Label if not via params? – Wabbitseason May 13 '16 at 7:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.