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

Add AddResourceOverriding functions in FluentBundle #54

Merged
merged 1 commit into from
Feb 1, 2024
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
53 changes: 37 additions & 16 deletions Linguini.Bundle/FluentBundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,33 @@ public bool AddResource(Resource res, [NotNullWhen(false)] out List<FluentError>
/// <param name="term">The term to be added.</param>
protected abstract void AddTermOverriding(AstTerm term);

private void InternalResourceOverriding(Resource resource)


/// <summary>
/// Adds a <c>string</c> resource to the FluentBundle, overriding any existing messages and terms with the same identifiers.
/// </summary>
/// <param name="input">The resource content to add.</param>
public void AddResourceOverriding(string input)
{
var res = new LinguiniParser(input, EnableExtensions).Parse();
AddResourceOverriding(res);
}

/// <summary>
/// Adds a <see cref="TextReader"/> to the FluentBundle, overriding any existing messages and terms with the same identifiers.
/// </summary>
/// <param name="input">The text reader to be added to parsed and added to bundle.</param>
public void AddResourceOverriding(TextReader input)
{
var res = new LinguiniParser(input, EnableExtensions).Parse();
AddResourceOverriding(res);
}

/// <summary>
/// Adds a <see cref="Resource"/> to the FluentBundle, overriding any existing messages and terms with the same identifiers.
/// </summary>
/// <param name="resource">The resource content to add.</param>
public void AddResourceOverriding(Resource resource)
{
for (var entryPos = 0; entryPos < resource.Entries.Count; entryPos++)
{
Expand All @@ -220,24 +246,19 @@ private void InternalResourceOverriding(Resource resource)
}

/// <summary>
/// Adds a resource.
/// Any messages or terms in bundle will be overriden by the existing ones.
/// Tries to add a term to the bundle.
/// </summary>
/// <param name="input">The input string containing the resource data.</param>
public void AddResourceOverriding(string input)
{
var res = new LinguiniParser(input, EnableExtensions).Parse();
InternalResourceOverriding(res);
}

public void AddResourceOverriding(TextReader input)
{
var res = new LinguiniParser(input, EnableExtensions).Parse();
InternalResourceOverriding(res);
}

/// <param name="term">The term to add.</param>
/// <param name="errors">A list to store any errors that occur during the <c>TryAdd</c> operation.</param>
/// <returns><see langword="true"/> if the term was added successfully, <see langword="false"/> otherwise.</returns>
protected abstract bool TryAddTerm(AstTerm term, [NotNullWhen(false)] List<FluentError>? errors);

/// <summary>
/// Tries to add a message to the bundle.
/// </summary>
/// <param name="msg">The message to add.</param>
/// <param name="errors">A list to store any errors that occur during the <c>TryAdd</c> operation.</param>
/// <returns><see langword="true"/> if the message was added successfully, <see langword="false"/> otherwise.</returns>
protected abstract bool TryAddMessage(AstMessage msg, [NotNullWhen(false)] List<FluentError>? errors);


Expand Down
2 changes: 1 addition & 1 deletion Linguini.Bundle/Linguini.Bundle.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ It provides easy to use and extend system for describing translations.</Descript
<Win32Resource />
<PackageProjectUrl>https://github.com/Ygg01/Linguini</PackageProjectUrl>
<RepositoryType>git</RepositoryType>
<PackageVersion>0.8.0</PackageVersion>
<PackageVersion>0.8.1</PackageVersion>
<TargetFrameworks>net8.0;netstandard2.1;net6.0</TargetFrameworks>
<PackageIcon>linguini.jpg</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ version 0.8.0

## What's Changed
* Remove `net5` or greater by
* Move to `net6` and/or `net8`.
* Move to `NUnit 4.0.1`
* Fix issue with Windows test not being fully run
* `[Breaking change]` Refactor to use consistent naming
Expand All @@ -199,3 +200,9 @@ version 0.8.0
```
* Adds `Equals` to most `Linguini.Syntax.Ast` types.
* All serializers now have a `Read` method implementation.

version 0.8.1
========

## What's changed
* Add `AddResourceOverriding(Resource res)`.
Loading