Skip to content

Commit

Permalink
Add AddResourceOverriding functions in FluentBundle (#54)
Browse files Browse the repository at this point in the history
The code introduces new `AddResourceOverriding` functions in the FluentBundle class. These functions allow adding a new resource to the bundle, while overriding any existing messages and terms with the same identifiers.

Also minor doc updates.

And remove qodana.yaml
  • Loading branch information
Ygg01 committed Feb 1, 2024
1 parent 81973d3 commit 21b6765
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 57 deletions.
53 changes: 37 additions & 16 deletions Linguini.Bundle/FluentBundle.cs
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
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
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)`.
40 changes: 0 additions & 40 deletions qodana.yaml

This file was deleted.

0 comments on commit 21b6765

Please sign in to comment.