question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rendering ordered/unordered lists from a translation string.

See original GitHub issue

🚀 Feature Proposal

I searched quite a while but couldn’t find a way to render basic HTML lists. Is there a recommended way output a plain HTML list from a translation string?

I did found the i18nIsDynamicList example, but that does not allow me to render content from the same translation string that is passed as key to the Trans component.

Motivation

I am using the Trans component with children to render dynamic and translated content. The dynamic content does require me to support adding ordered and unordered lists.

Example

Im looking for something in the likes of:

<Trans i18nKey="list_map">
  My cats are named:
  <ul>
     <li>Milo</li>
     <li>Simba</li>
  </ul>
  and they are very sweet.
</Trans>

// JSON -> "list_map": "My dogs are named: <1><2>Ace</2><2>Diesel</2><2>Finn</2></1>"

// Which would output:

//  My dogs are named:
//  <ul>
//     <li>Ace</li>
//     <li>Diesel</li>
//     <li>Finn</li>
//  </ul>
//  and they are very sweet.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
wilbocommented, Jun 16, 2020

Thanks for your quick reply. I managed to create a working solution by updating the nested index elements to 0. I did not now that nested children would reset its index to 0.


// JSON -> "list_map": "My dogs are named: <1><0>Ace</0><0>Diesel</0><0>Finn</0></1> and they are very sweet."

<Trans i18nKey="list_map">
  My cats are named:
  <ul>
    <li>Milo</li>
    <li>Simba</li>
  </ul>
  and they are very sweet.
</Trans>

0reactions
baxromxojasultonxojayevcommented, Aug 31, 2021

how can I iterate array elements to unrodered list with map

{t("text", { returnObject: true }).map((text, country_code) => (
{text}
))} 

when I do this it gives me t(…).map is not a function

Read more comments on GitHub >

github_iconTop Results From Across the Web

l10n/i18n: how to handle phrases with dynamic list of items?
To render a list, I would use a couple of format strings, e.g.: joinItem = "{LIST}, {ITEM}" to append items to the list...
Read more >
apex - Render Set as Unordered List - Salesforce Stack Exchange
Sets are unordered lists that don't contain duplicates. ... If you need an ordered list you should use a List<String> collection.
Read more >
list-style - CSS: Cascading Style Sheets - MDN Web Docs
The list-style CSS shorthand property allows you to set all the list ... Safari will not recognize an ordered or unordered list as...
Read more >
Lists in HTML documents
Ordered and unordered lists are rendered in an identical manner except that visual user agents number ordered list items. User agents may present...
Read more >
List Rendering - Vue.js
We can use the v-for directive to render a list of items based on an array. ... The iteration order will be based...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found