Skip to content

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

Merged
merged 2 commits into from
Jun 4, 2020
Merged

Conversation

cknitt
Copy link
Member

@cknitt cknitt commented May 23, 2020

@alexfedoseev Also, I moved the translation type from the ReactIntl module to the Util module, as it is actually not used anywhere but in Util.

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.

@cknitt cknitt requested a review from alex35mil May 23, 2020 07:18
@ixzzd
Copy link

ixzzd commented May 26, 2020

@cknitt Do you have plans to keep description field support?

open ReactIntl;
[@intl.messages];

let hello = {id: "page.hello", defaultMessage: "Hello"};
Copy link

@ixzzd ixzzd May 27, 2020

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

Copy link
Member Author

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.

Copy link

@ixzzd ixzzd Jun 1, 2020

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"};

Copy link
Collaborator

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.

Copy link
Member Author

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. 😉

Copy link
Collaborator

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"}];

Copy link

@ixzzd ixzzd Jun 4, 2020

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.

Copy link
Collaborator

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].

@cknitt
Copy link
Member Author

cknitt commented May 27, 2020

@cknitt Do you have plans to keep description field support?

@ixzzd I agree that it would be nice to have a way to support a description field (see also #5 which I opened quite some time ago 😉).

However, I could not really think of a good solution. I would not like to have to add description: None everywhere, as in

let hello = {id: "page.hello", defaultMessage: "Hello", description: None};

Do you have any suggestion for a better approach?

@ixzzd
Copy link

ixzzd commented Jun 1, 2020

I would not like to have to add description: None everywhere

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 :(

Copy link
Collaborator

@alex35mil alex35mil left a 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"};
Copy link
Collaborator

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 = {
Copy link
Collaborator

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 = ...;

Copy link
Collaborator

@alex35mil alex35mil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks perfect 👍

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

Successfully merging this pull request may close these issues.

3 participants