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

withLocalization's getString API is missing the elems parameter #544

Closed
canova opened this issue Apr 8, 2021 · 1 comment · Fixed by #595
Closed

withLocalization's getString API is missing the elems parameter #544

canova opened this issue Apr 8, 2021 · 1 comment · Fixed by #595

Comments

@canova
Copy link
Contributor

canova commented Apr 8, 2021

We are usually using the Localized component, but recently I was trying the withLocalization's getString API, and it looks like it is the missing the elems parameter, which is pretty commonly used in Firefox Profiler.

Also wiki seems to be missing more advanced usage information. It's not possible to see other parameters here: https://github.com/projectfluent/fluent.js/wiki/withLocalization

So, I tried to check the implementation of getString and realized that it doesn't have a elems parameter, like Localized:

getString(
id: string,
args?: Record<string, FluentVariable> | null,
fallback?: string
): string {
const bundle = this.getBundle(id);
if (bundle) {
const msg = bundle.getMessage(id);
if (msg && msg.value) {
let errors: Array<Error> = [];
let value = bundle.formatPattern(msg.value, args, errors);
for (let error of errors) {
this.reportError(error);
}
return value;
}
}
return fallback || id;
}

Maybe there can be another way to pass these elements after getting the string, but I don't know how. I think it would be great to have an optional elems parameter inside the getString directly, so we can add elements directly with that API call.

To be clear, we are not blocked on this since Localized is fixed now and we can continue using that. But it would be good to have this as well. What do you think?

@Vinnl
Copy link
Contributor

Vinnl commented Jul 9, 2022

I've often wanted similar functionality, so I just submitted a PR: #595

No idea if it fits with the project goals, but might at least be worth subscribing to for people interested in this issue :)

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

Successfully merging a pull request may close this issue.

3 participants