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

Refactor to use consistent naming #42

Merged
merged 2 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Linguini.Bundle.Test/Unit/BundleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ [other] Dogs
[TestCase(DynRef)]
public void TestDynamicReference(string input)
{
var (bundle, err) = LinguiniBuilder.Builder(extension: true).Locale("en-US")
var (bundle, err) = LinguiniBuilder.Builder(useExperimental: true).Locale("en-US")
.AddResource(input)
.Build();
Assert.IsEmpty(err);
Expand Down Expand Up @@ -314,7 +314,7 @@ [neuter] It
[Parallelizable]
public void TestMacrosFail()
{
var (bundle, err) = LinguiniBuilder.Builder(extension: true).Locale("en-US")
var (bundle, err) = LinguiniBuilder.Builder(useExperimental: true).Locale("en-US")
.AddResource(Macros)
.Build();
Assert.IsEmpty(err);
Expand All @@ -340,7 +340,7 @@ [vowel] an { $$object }
[Parallelizable]
public void TestDynamicSelectors()
{
var (bundle, err) = LinguiniBuilder.Builder(extension: true)
var (bundle, err) = LinguiniBuilder.Builder(useExperimental: true)
.Locale("en-US")
.AddResource(DynamicSelectors)
.Build();
Expand Down
8 changes: 4 additions & 4 deletions Linguini.Bundle.Test/Yaml/YamlSuiteParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,17 @@ private static LinguiniBuilder.IReadyStep ParseDefault(string path)

List<string> locales = new();
var isIsolating = false;
var useExtensions = false;
var useExperimental = false;
if (yamlBundle is YamlMappingNode map)
{
if (map.TryGetNode("useIsolating", out YamlScalarNode? useIsolatingNode))
{
isIsolating = useIsolatingNode.AsBool();
}

if (map.TryGetNode("useExtensions", out YamlScalarNode? useExtensionsNode))
if (map.TryGetNode("useExperimental", out YamlScalarNode? useExtensionsNode))
{
useExtensions = useExtensionsNode.AsBool();
useExperimental = useExtensionsNode.AsBool();
}

if (map.TryGetNode("locales", out YamlSequenceNode? localesNode))
Expand All @@ -252,7 +252,7 @@ private static LinguiniBuilder.IReadyStep ParseDefault(string path)
}
}

var bundler = LinguiniBuilder.Builder(useExtensions)
var bundler = LinguiniBuilder.Builder(useExperimental)
.Locales(locales)
.SkipResources()
.SetUseIsolating(isIsolating);
Expand Down
2 changes: 1 addition & 1 deletion Linguini.Bundle.Test/linguini_ext/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

bundle:
useIsolating: false
useExtensions: true
useExperimental: true
locales:
- en-US
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
attack-log1 = { $$attacker($atk_num) } attacked {$$defender($def_num)}.
attack-log2 = { $$attacker(number: $atk_num) } attacked {$$defender(number: $def_num)}.
bundles:
- useExtensions: true
- useExperimental: true
tests:
- name: regular reference
asserts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*[consonant] a { $$object }
}.
bundles:
- useExtensions: true
- useExperimental: true
tests:
- name: regular reference
asserts:
Expand Down
2 changes: 1 addition & 1 deletion Linguini.Bundle.Test/linguini_ext/linguini_term_pass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[neuter] It
}
bundles:
- useExtensions: true
- useExperimental: true
tests:
- name: regular reference
asserts:
Expand Down
8 changes: 4 additions & 4 deletions Linguini.Bundle/Builder/LinguiniBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ namespace Linguini.Bundle.Builder
{
public static class LinguiniBuilder
{
public static ILocaleStep Builder(bool extension = false)
public static ILocaleStep Builder(bool useExperimental = false)
{
return new StepBuilder(extension);
return new StepBuilder(useExperimental);
}

public interface IStep
Expand Down Expand Up @@ -73,10 +73,10 @@ private class StepBuilder : IReadyStep, ILocaleStep, IResourceStep
private bool _concurrent;
private readonly bool _enableExperimental;

internal StepBuilder(bool isExperimental = false)
internal StepBuilder(bool useExperimental = false)
{
_culture = System.Globalization.CultureInfo.CurrentCulture;
_enableExperimental = isExperimental;
_enableExperimental = useExperimental;
}

public IReadyStep SetUseIsolating(bool isIsolating)
Expand Down
31 changes: 29 additions & 2 deletions Linguini.Bundle/FluentBundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,41 @@ public class FluentBundle
private IDictionary<(string, EntryKind), IEntry> _entries;

#region Properties

/// <summary>
/// <see cref="CultureInfo"/> of the bundle. Primary bundle locale
/// </summary>
public CultureInfo Culture { get; internal set; }
/// <summary>
/// List of Locales. First element is primary bundle locale, others are fallback locales.
/// </summary>
public List<string> Locales { get; internal set; }
/// <summary>
/// When formatting patterns, FluentBundle inserts Unicode Directionality Isolation Marks to indicate that the direction of a placeable may differ from the surrounding message.
/// This is important for cases such as when a right-to-left user name is presented in the left-to-right message.
/// </summary>
public bool UseIsolating { get; set; }
/// <summary>
/// Specifies a method that will be applied only on values extending <see cref="IFluentType"/>. Useful for defining a special formatter for <see cref="FluentNumber"/>.
/// </summary>
public Func<string, string>? TransformFunc { get; set; }
/// <summary>
/// Specifies a method that will be applied only on values extending <see cref="IFluentType"/>. Useful for defining a special formatter for <see cref="FluentNumber"/>.
/// </summary>
public Func<IFluentType, string>? FormatterFunc { get; init; }
/// <summary>
/// Limit of placeable <see cref="AstTerm"/> within one <see cref="Pattern"/>, when fully expanded (all nested elements count towards it). Useful for preventing billion laughs attack. Defaults to 100.
/// </summary>
public byte MaxPlaceable { get; private init; }

/// <summary>
/// Whether experimental features are enabled.
///
/// When `true` experimental features are enabled. Experimental features include stuff like:
/// <list type="bullet">
/// <item>dynamic reference</item>
/// <item>dynamic reference attributes</item>
/// <item>term reference as parameters</item>
/// </list>
/// </summary>
public bool EnableExtensions { get; init; }

#endregion
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ version 0.7.0

- Term passing - experimental feature allows users to override term arguments.
```fluent
# ship_gender.ftl
-ship = Ship
.gender = { $style ->
*[traditional] neuter
Expand Down
Loading