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.

Feature: add metadata to translations

See original GitHub issue

I want to add some metadata to translations, which would also be extracted during lingui extract process.

Use case: I want to specify the type of the translation, and later, in the CMS, present the user with a different editor based on the translation type.

<h1 className="title">
    <Trans id="home.title" type="text">Page title</Trans>
</h1>
<p className="lead">
    <Trans id="home.lead"" type="textarea">Some long text, bla bla. Users will expect textarea or maybe even rich text editor</Trans>
</p>

I can write a custom extractor to do this, but I was thinking that maybe we can add support for this directly to the Lingui library. What do you think? Does it make sense to put metadata on translations?

To be honest, I haven’t really thought things through 😃 I mean, I could easily write my message ids like ${ns}.${key}.${type} 😃

<Trans id="home.title.text" />
or
<Trans id="home.lead.textarea" />

Issue Analytics

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

github_iconTop GitHub Comments

5reactions
tricoder42commented, Apr 2, 2018

Yeah, it should be possible to add metadata when using lingui format.

One metadata I have thought about was help text for translators:

{/* i18n: Month */}
<Trans>May</Trans>

This would be extracted as:

{
  "May": {
    "translation": "",
    "help": "Month",
    "origin": [...]
  }
}

We might use similar syntax to add other meta tags depending on usecase.

I’m not 100% convinced about type as it could be guessed from content (e.g: type = text, markdown, icu).

3reactions
tricoder42commented, Aug 21, 2018

RFC - support metadata in js.macro

t macro is the same as i18n.t what we have now. If we want to add support for metadata, we need to figure out all possible variation, how the macro is used.

Description is type Description = string | Object, where object might contain arbitrary data. Using string is a shortcut for { description: string } object.

The problem is, that using Description as a string clashes with message ID, which is also a string. In simple usecase t("hello")'Message' it’s impossible to determine whether hello is ID or description.

Please vote with reaction or suggest different API.

Variation 👍

t template tag is used for all messages. Description must be always second argument.

// Message used as an ID, without description
t`Default message`

// Message with custom ID, without description
t("message.id")`Default message`

// Message with custom ID and description
t("message.id", "description")`Default message`

// Message used as an ID, with description
t(null, "description")`Default message`

Variation ❤️

t template tag is used only for messages used as IDs, t.id template tag is used for messages with custom IDs

// Message used as an ID, without description
t`Default message`

// Message used as an ID, with description
t("description")`Default message`

// Message with custom ID, without description
t.id("message.id")`Default message`

// Message with custom ID and description
t.id("message.id", "description")`Default message`
``
Read more comments on GitHub >

github_iconTop Results From Across the Web

Translating Metadata to a Different Language
You can translate your metadata by modifying the default values using a JavaScript add-on. Through the add-on, you define the new values to...
Read more >
Metadata Translation
In situations where Salesforce doesn't provide default translations, metadata translation allows you to localize apps and custom functionality that you build in ...
Read more >
Provide metadata translations in bulk
Import translated metadata · Open the Items page icon · Click the arrow next to the Add new items button · Choose Advanced...
Read more >
Automating Translations of Asset Metadata
Translate Metadata Fields · Loop over each of the metadata fields that require translation and call the custom block with sourceText , ...
Read more >
Import metadata translation - Power Apps
To import metadata translation · Open Power Apps portals admin center. · Go to Portal Actions > Get latest metadata translations. A confirmation ......
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