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 dyn refs #39

Merged
merged 12 commits into from
Oct 24, 2023
Merged

New dyn refs #39

merged 12 commits into from
Oct 24, 2023

Conversation

Ygg01
Copy link
Owner

@Ygg01 Ygg01 commented Oct 24, 2023

Dynamic Reference feature

Adds Message Reference as mentioned in #27

Following expressions are now legal is isExperimenal flag in FluentBundle is enabled. It defaults to false.

Message bundle:

# example.ftl
cat = {$number ->
  *[one] Cat
  [other] Cats
}
dog = {$number -> 
  *[one] Dog
  [other] Dogs
}

attack-log = { $$attacker(number: $atk_num) } attacked {$$defender(number: $def_num)}.

Can be parsed as:

var bundle = LinguiniBuilder.Builder(isExperimenal = true)
                .Locales(locales)
                .SkipResources(example)
                .UncheckedBuild();
var actual = bundle.GetAttrMessage("attack-log", ("cat", (FluentNumber) 1), ("dog", (FluentNumber) 2));

Assert.AreEqual("Cat attacked Dogs", actual);

Dynamic reference attributes

In addition to dynamic references, dynamic references will also use their attribute if available:

-creature-fairy = fairy
-creature-elf = elf
   .StartsWith = vowel

you-see = You see { $$object.StartsWith ->
    [vowel] an { $$object }
    *[consonant] a { $$object }
}.

Will dynamically change its attributes:

var elf = bundle.GetAttrMessage("you-see", ("object", "elf"));
var fairy= bundle.GetAttrMessage("you-see", ("object", "fairy"));

Assert.AreEqual("You see an elf", elf);
Assert.AreEqual("You see a fairy", fairy);

Closes #27

@github-actions
Copy link

Qodana for .NET

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ View the detailed Qodana report

Contact Qodana team

Contact us at [email protected]

@Ygg01 Ygg01 merged commit 21367b4 into master Oct 24, 2023
5 checks passed
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.

Add Message Reference (Linguini extension of Fluent)
1 participant