Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Allow no-op/lazy translations #60

Closed
tricoder42 opened this issue Aug 14, 2017 · 7 comments
Closed

Feature request: Allow no-op/lazy translations #60

tricoder42 opened this issue Aug 14, 2017 · 7 comments

Comments

@tricoder42
Copy link
Contributor

Followup from #53

Sometimes it's necessary to mark strings which will be translated in the future, but leave them intact for now:

import { Trans, noop } from 'lingui-react'

const menu = [
  { to: '/about', title: noop('About') },
  { to: '/contact', title: noop('Contact') },
]

// later in the code
const Menu = () => 
  <div>{
    menu.map(item => 
      <Link to={item.to}>
        <Trans id={item.title} />
      </Link>)
  }</div>
@vitexikora
Copy link

IMHO the method should be named most closely to what it actually does, which in this case is something like 'markForTranslation/Extraction', 'addTranslation', 'linguiString', or even 'internationalize', rather than 'noop'... Looking at this example code I would have no idea what it does. Just an opinion.

@tricoder42
Copy link
Contributor Author

Yeah I have similar concern. I know this naming from Django, but there is ugettext_noop so you at least know that it's related to gettext.

It's basically i18n.t without the translation, so maybe i18n_noop, i18n_mark, i18n_add, i18n_dummy, i18n_future, i18n_lazy (it could be also considered as "lazy" translation).

From your examples I'm considering markForTranslation 🤔

@vitexikora
Copy link

May I ask, how is this feature looking? I am really looking forward to it 👍 😊

@tricoder42
Copy link
Contributor Author

I was a bit busy in last few weeks, so I was happy to find at least some time to refactor cli.

However, this should be very easy, I'll take a look this week.

If you want to work on this, it's basically just:

  1. Add another node matcher, similar to this: https://github.com/lingui/js-lingui/blob/master/packages/babel-plugin-lingui-transform-js/src/index.js#L7
  2. Make sure, we replace node with source string, not i18n.t call here: https://github.com/lingui/js-lingui/blob/master/packages/babel-plugin-lingui-transform-js/src/index.js#L218

I would go with following syntax:

import { i18n_noop } from 'lingui-i18n'

const languages = {
  en: i18n_noop('English'),
  cs: i18n_noop('Czech')
}

which would be transformed to

const languages = {
  en: 'English',
  cs: 'Czech'
}

Question is, how to handle translations with variables? 🤔 Should i18n_noop support only static translations?

@vitexikora
Copy link

Thats ok, its still cool, you have time to improve this lib and push it further 👍 Doesnt have to be all at once..

Should i18n_noop support only static translations?

Given the typical usage of such function, I guess it should not be a problem. I would make it static and create an enhancement issue with a very low priority on it supporting even variables and tags. Just to keep all functions consistent, because I can imagine (in the future) people misusing this function and wondering why it doesnt work with variables.

@tricoder42
Copy link
Contributor Author

Alright, added in latest releases:

  • lingui-cli@1.3.2
  • lingui-i18n@1.3.0
  • lingui-react@1.2.0

The function is named i18nMark after all. See the docs for more info.

@vitexikora
Copy link

Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants