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

[New] support custom replace implementation #171

Merged
merged 1 commit into from
Jun 29, 2022

Conversation

Xiphe
Copy link
Contributor

@Xiphe Xiphe commented Jun 11, 2022

in order to support interpolating types other then strings

as described in #170 this aims to allow use of complex types (like UI components) in interpolation slots.

const p = new Polyglot({ phrases: { hello: 'Hello %{name}' } });
ReactDom.render(p.t(
  'hello',
  {
    name: <a href="https://example.org/">Example</a>
  }
))

Pre-Released this as @xiphe/[email protected].

Here is a working example with dynamic and nested components: https://codesandbox.io/s/admiring-framework-lb367l?file=/src/App.js

in order to support interpolating types other then strings

fix airbnb#170
index.js Outdated
Polyglot.transformPhrase = function transform(phrase, substitutions, locale) {
return transformPhrase(phrase, substitutions, locale);
};
Polyglot.transformPhrase = transformPhrase;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one is optional. I'm not sure if the api intentionally excludes custom tokens or plural rules here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It does intentionally exclude them.

@Xiphe
Copy link
Contributor Author

Xiphe commented Jun 11, 2022

I'll gladly add docs and types if you think this is valuable for the library

@Xiphe
Copy link
Contributor Author

Xiphe commented Jun 22, 2022

@ljharb sorry to bother you. Have you had the chance to have a look on this?

It would really help me to know if this is going into a direction that you'd consider valuable for polyglot or not.

@ljharb
Copy link
Collaborator

ljharb commented Jun 22, 2022

@Xiphe no, i haven't had time yet, but i will take a look soon.

index.js Outdated
Polyglot.transformPhrase = function transform(phrase, substitutions, locale) {
return transformPhrase(phrase, substitutions, locale);
};
Polyglot.transformPhrase = transformPhrase;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It does intentionally exclude them.

@Xiphe Xiphe requested a review from ljharb June 28, 2022 07:22
test/index.js Outdated Show resolved Hide resolved
test/index.js Outdated Show resolved Hide resolved
test/index.js Outdated Show resolved Hide resolved
@Xiphe Xiphe requested a review from ljharb June 28, 2022 21:49
@ljharb ljharb merged commit 01262a0 into airbnb:master Jun 29, 2022
@ljharb
Copy link
Collaborator

ljharb commented Jun 29, 2022

hmm, this actually broke tests in node 0.8 and 0.10; something needs a bit more work here.

@ljharb
Copy link
Collaborator

ljharb commented Jun 29, 2022

Fixed in #172.

@Xiphe Xiphe deleted the custom-replace branch June 30, 2022 08:18
@Xiphe
Copy link
Contributor Author

Xiphe commented Jun 30, 2022

Cool! Thanks for the integration and follow up 👍
Will add docs+types asap.

@Xiphe Xiphe mentioned this pull request Jul 7, 2022
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.

2 participants