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

Position indepentent parameters #96

Open
jeduden opened this issue Oct 5, 2021 · 1 comment
Open

Position indepentent parameters #96

jeduden opened this issue Oct 5, 2021 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@jeduden
Copy link

jeduden commented Oct 5, 2021

Since fill uses sprintf, parameters depend on the position in the translation.
Sometimes it can make sense to swap the placeholders.

Further providing names to placeholders can help translators to find the right translation.

I have written an additional extension method fillMap that does this:

Here are few statements from the unit-tests:

expect("doesnt need any placeholder".fillMap({"unused": 3}),
            "doesnt need any placeholder");

expect("<placeholder%d> and <placeholder%03d>".fillMap({"placeholder": 3}),
            equals("3 and 003"));

expect("<placeholder>".fillMap({"placeholder": 3}), equals("3"));

expect("<placeholder/>".fillMap({"placeholder": 3}), equals("3"));  /// optional  / to make it look like a standalone html tag. helps with automatic translation tools, that sometime expand <placehoder> to <placeholder></placeholder>. 

expect(() => "some <placeholder>".fillMap({}), throwsFormatException);

expect("<placeholder%d> and <other>".fillMap({"other": 3}, keep: {"placeholder"}),
            equals("<placeholder%d> and 3"));

Would you accept a PR to add this method to your repo ?

@marcglasberg
Copy link
Owner

I like your idea. And yes, I would accept it.

@marcglasberg marcglasberg added enhancement New feature or request help wanted Extra attention is needed labels Nov 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants