-
Notifications
You must be signed in to change notification settings - Fork 7
Change message and translation to record types #31
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
Conversation
@cknitt Do you have plans to keep |
open ReactIntl; | ||
[@intl.messages]; | ||
|
||
let hello = {id: "page.hello", defaultMessage: "Hello"}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to current PR, but maybe there is a way to generate ids with the PPX too? It could be great
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which PPX are you referring to? bs-react-intl-extractor is not a PPX and can only extract existing messages.
But yes, it might be nice to have a PPX that could extract a message with id PageLocale.hello
and defaultMessage Hello
from module PageLocale.re
with
let hello = [%intl.msg "Hello"];
or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which PPX are you referring to?
There is not such ppx yet, it exists only in my dreams :) But maybe I can find time to work on it. I an ppx noob, but I think it should be possible to use ppx-per file, not ppx-per-constant.
[@intl.someppx];
let hello = {defaultMessage: "Hello", description: None};
let world = {defaultMessage: "world", description: "world description"};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be
let a = [%intl.msg {id: "a", message: "message a"}];
let b = [%intl.msg
{id: "b", message: "message b", description: "description b"}
];
Or
let a = [@intl.msg] {id: "a", message: "message a"};
let b = [@intl.msg]
{id: "b", message: "message b", description: "description b"};
But the latter would produce a confusing error in case of a typo in an attribute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not specify the id explicitly, but just use <module name>.<variable name>
as the id automatically.
Anyway, let's leave this for a possible future PR. 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌 I think I saw ppx that does this id thing.
It can even be
let a = [%intl.msg "message a"];
let b = [%intl.msg {message: "message b", description: "description b"}];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexfedoseev this is great! But is it possible to use ppx only once at the beginning of the module?
[%intl.msgmodule]
let a = "message a";
let b = {message: "message b", description: "description b"};
For example, [@bs.config {jsx: 2}];
works for the whole module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ixzzd I don't think it's possible since PPX wouldn't capture outside things. I'm not sure how exactly [@bs.config {jsx: 2}]
works but guessing it's an attribute that is used by the compiler to figure how to handle the current module, i.e. it's not handled by the PPX engine. The same way as the extractor consumes [@intl.messages]
.
@ixzzd I agree that it would be nice to have a way to support a However, I could not really think of a good solution. I would not like to have to add let hello = {id: "page.hello", defaultMessage: "Hello", description: None}; Do you have any suggestion for a better approach? |
My opinion- it is better to have it everywhere than doesn't have it at all, but I don't see any better solution than yours :( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great! One small comment.
open ReactIntl; | ||
[@intl.messages]; | ||
|
||
let hello = {id: "page.hello", defaultMessage: "Hello"}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be
let a = [%intl.msg {id: "a", message: "message a"}];
let b = [%intl.msg
{id: "b", message: "message b", description: "description b"}
];
Or
let a = [@intl.msg] {id: "a", message: "message a"};
let b = [@intl.msg]
{id: "b", message: "message b", description: "description b"};
But the latter would produce a confusing error in case of a typo in an attribute.
examples/Util.re
Outdated
@@ -1,12 +1,18 @@ | |||
let translationsToDict = (translations: array(ReactIntl.translation)) => { | |||
type translation = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would name this module Translation
then:
// Translation.re
type t = ...;
let toDict = ...;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks perfect 👍
@alexfedoseev Also, I moved the
translation
type from theReactIntl
module to theUtil
module, as it is actually not used anywhere but inUtil
.Note that I still need to release a new version of the extractor to make message extraction from PageLocale.re work again. I will do that once we have this PR merged.