Translating the render array key like "Super simple #markup" is confusing.

Why we should remove it:
- confusing
- If someone do that on a "real" module you can end up with strange bugs...
- code harder to read
- translating "code" doesn't make sens as PHP is in English (you don't translate code comment).


function render_example_arrays() {

  $interval = 60; // Interval in seconds for cache update with #cache.

  $demos = array(
    // Demonstrate the simplest markup, a #markup element.
    t('Super simple #markup')  => array(
      '#markup' => t('Some basic text in a #markup (shows basic markup and how it is rendered)'),
    ),

    // Shows how #prefix and #suffix can add markup into an array.
    t('Using #prefix and #suffix') => array(
      '#markup' => t('This one adds a prefix and suffix, which put a div around the item'),
      '#prefix' => '<div><br/>(prefix)<br/>',
      '#suffix' => '<br/>(suffix)</div>',
    ),
 //...

Comments

Mile23’s picture

Status: Active » Closed (works as designed)

render_example requires devel module to show you the render arrays. The keys are shown as content titles, which is less than great, but also kind of clever...

Anyway, someone might come along and translate the module, in which case that content could be translated. It's best practice to wrap t() around static content, though as you point out, this is a strange edge case.

Go ahead and change the status of this issue and ask for clarification if it's not clear.

gagarine’s picture

Title: Why render array example use t() for the array key? » Render array example use t() for the array key whitch is confusing
Category: Support request » Bug report
Issue summary: View changes
Status: Closed (works as designed) » Active

Ok, so in my point of view we should remove this because. If you don't know Drupal this can be confusing. I think if you can't understand "title" in English their is almost no chance you can be a programer.

So if you agree I will be happy to provide a patch.

Mile23’s picture

Just so you understand the problem... If you install the module and go to this path: examples/render_example/arrays, you'll see the render arrays presented as arrays using the devel module's fancy array printer, next to the content those arrays turn into.

Since the key strings are descriptive for humans, we wrap them in t(), because that's a Drupal best practice for static content provided by modules.

Yes, it's a workaround, and yes it can be confusing, so if you can think of a better way to: 1) Show those arrays next to their content on the web page, 2) maintain the t() best practice, and 3) not be confusing, then I'd be happy to see it.

Thanks.

jungle’s picture

Status: Active » Closed (outdated)

No activity for over 9 years. I am closing this. Please feel free to reopen if necessary.

Thanks!