From 21b67654fc373a85c4f791d48b14e3c5ffa7e071 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. Also minor doc updates. And remove qodana.yaml --- Linguini.Bundle/FluentBundle.cs | 53 ++++++++++++++++++-------- Linguini.Bundle/Linguini.Bundle.csproj | 2 +- changelog.md | 7 ++++ qodana.yaml | 40 ------------------- 4 files changed, 45 insertions(+), 57 deletions(-) delete mode 100644 qodana.yaml 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 diff --git a/qodana.yaml b/qodana.yaml deleted file mode 100644 index 1e07777..0000000 --- a/qodana.yaml +++ /dev/null @@ -1,40 +0,0 @@ -#-------------------------------------------------------------------------------# -# Qodana analysis is configured by qodana.yaml file # -# https://www.jetbrains.com/help/qodana/qodana-yaml.html # -#-------------------------------------------------------------------------------# -version: "1.0" - -#Specify inspection profile for code analysis -profile: - name: qodana.starter - -#Enable inspections -#include: -# - name: - -#Disable inspections -#exclude: -# - name: -# paths: -# - - -#Execute shell command before Qodana execution (Applied in CI/CD pipeline) -#bootstrap: sh ./prepare-qodana.sh - -#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline) -#plugins: -# - id: #(plugin id can be found at https://plugins.jetbrains.com) - -#Specify Qodana linter for analysis (Applied in CI/CD pipeline) -linter: jetbrains/qodana-dotnet:latest -exclude: - - name: All - paths: - - Linguini.Bundle\IsExternalInit.cs - - name: CheckNamespace - paths: - - Linguini.Bundle\IsExternalInit.cs - - name: HeapView.ObjectAllocation.Evident - - name: HeapView.DelegateAllocation - - name: HeapView.BoxingAllocation - - name: HeapView.ClosureAllocation