From 1dd9276df319fb9dbffffb969839065349ce1c85 Mon Sep 17 00:00:00 2001 From: Ygg01 Date: Thu, 1 Feb 2024 19:59:44 +0100 Subject: [PATCH] Add AddResourceOverriding functions in FluentBundle (#54) 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. --- Linguini.Bundle/FluentBundle.cs | 53 ++++++++++++++++++-------- Linguini.Bundle/Linguini.Bundle.csproj | 2 +- changelog.md | 7 ++++ 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/Linguini.Bundle/FluentBundle.cs b/Linguini.Bundle/FluentBundle.cs index 04ed59e..c4b2a27 100644 --- a/Linguini.Bundle/FluentBundle.cs +++ b/Linguini.Bundle/FluentBundle.cs @@ -201,7 +201,33 @@ public bool AddResource(Resource res, [NotNullWhen(false)] out List /// The term to be added. protected abstract void AddTermOverriding(AstTerm term); - private void InternalResourceOverriding(Resource resource) + + + /// + /// Adds a string resource to the FluentBundle, overriding any existing messages and terms with the same identifiers. + /// + /// The resource content to add. + public void AddResourceOverriding(string input) + { + var res = new LinguiniParser(input, EnableExtensions).Parse(); + AddResourceOverriding(res); + } + + /// + /// Adds a to the FluentBundle, overriding any existing messages and terms with the same identifiers. + /// + /// The text reader to be added to parsed and added to bundle. + public void AddResourceOverriding(TextReader input) + { + var res = new LinguiniParser(input, EnableExtensions).Parse(); + AddResourceOverriding(res); + } + + /// + /// Adds a to the FluentBundle, overriding any existing messages and terms with the same identifiers. + /// + /// The resource content to add. + public void AddResourceOverriding(Resource resource) { for (var entryPos = 0; entryPos < resource.Entries.Count; entryPos++) { @@ -220,24 +246,19 @@ private void InternalResourceOverriding(Resource resource) } /// - /// Adds a resource. - /// Any messages or terms in bundle will be overriden by the existing ones. + /// Tries to add a term to the bundle. /// - /// The input string containing the resource data. - 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); - } - + /// The term to add. + /// A list to store any errors that occur during the TryAdd operation. + /// if the term was added successfully, otherwise. protected abstract bool TryAddTerm(AstTerm term, [NotNullWhen(false)] List? errors); + /// + /// Tries to add a message to the bundle. + /// + /// The message to add. + /// A list to store any errors that occur during the TryAdd operation. + /// if the message was added successfully, otherwise. protected abstract bool TryAddMessage(AstMessage msg, [NotNullWhen(false)] List? errors); diff --git a/Linguini.Bundle/Linguini.Bundle.csproj b/Linguini.Bundle/Linguini.Bundle.csproj index 69b93d4..17796f4 100644 --- a/Linguini.Bundle/Linguini.Bundle.csproj +++ b/Linguini.Bundle/Linguini.Bundle.csproj @@ -18,7 +18,7 @@ It provides easy to use and extend system for describing translations. https://github.com/Ygg01/Linguini git - 0.8.0 + 0.8.1 net8.0;netstandard2.1;net6.0 linguini.jpg README.md diff --git a/changelog.md b/changelog.md index 00b98f5..1c90381 100644 --- a/changelog.md +++ b/changelog.md @@ -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 @@ -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)`. \ No newline at end of file