akameco / babel-plugin-react-intl-auto

i18n for the component age. Auto management react-intl ID.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possibility to define prefix in leading comment (file scope)

langpavel opened this issue · comments

Do you want to request a feature or report a bug?:
feature

Suggested solution:

In source, before first use of defineMessages or FormattedMessage

// @intl some.leading.string.
/* @msg-scope some.leading.string. */
// $intl-namespace some.leading.string.
// #intlPrefix some.leading.string.
// …

I'm not sure about format, but this can be definitely controlled by configurable regular expression

Including comment like this you can control prefix which is by default autogenerated as this module propose.

This can enable more robust application architecture

Also warnings in case that this prefix is used can be enforced;
In contrary warnings in case when leading comment is missing should be possibly turned on too.

What do you think? I'm apologise when I'm not exact…

@langpavel Interesting!!😳

However, I think that the edge case will increase.
For example, what if you accidentally specify the same prefix with a different file?

file1.js

// @intl same.prefix
import {defineMessages} from 'react-intl';

export default defineMessages ({
   hello: 'hello world'
});
// => same.prefix.hello

file2.js

// @intl same.prefix
import {defineMessages} from 'react-intl';

export default defineMessages ({
   hello: 'hello {name}' // different value
});
// => same.prefix.hello ← Oops!

And I want to avoid complicating the library.

Perhaps it would be better to create a different library 👍

@akameco

For example, what if you accidentally specify the same prefix with a different file?

This should be perfectly legal except when you clash with names, like you did with hello

And I want to avoid complicating the library. Perhaps it would be better to create a different library

Considering this. Anyway thank you! 🙂