Skip to content

added support for column name localization #56

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

Merged
merged 3 commits into from
May 20, 2024

Conversation

Mitroz
Copy link
Contributor

@Mitroz Mitroz commented Oct 4, 2023

There is a simple test included but I don't know how to verify in the test that the column in the result file is correctly localized.
I have manually verified this and am already using it successfully in my project.
Thanks

Summary by CodeRabbit

  • New Features

    • Introduced localization support for spreadsheets, enabling the creation of sheets with localized column names.
    • Added a new class for localized export records.
    • Added properties to support resource file type and key for spreadsheet columns.
  • Tests

    • Added new test method to validate the creation of spreadsheets with localized column names.
    • Updated test resources and configurations to support localization testing.
  • Localization

    • Added Czech language support for test resources.

Copy link
Contributor

@mitchelsellers mitchelsellers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mitroz I am so sorry for the delayed approval of this change, we will get a new release coming soon with this included!

@mitchelsellers mitchelsellers merged commit 921561e into IowaComputerGurus:develop May 20, 2024
1 of 2 checks passed
Copy link

coderabbitai bot commented May 20, 2024

Walkthrough

The update enhances the NetCore.Utilities.Spreadsheet library by introducing localization support for spreadsheet column names. It includes new resource files for localization, test methods to validate these features, and additional properties in the SpreadsheetColumnAttribute class for specifying resource files and keys. The changes ensure that column names in generated spreadsheets can be localized based on culture settings, improving the library's versatility and usability in multilingual environments.

Changes

File Path Change Summary
src/.../NetCore.Utilities.Spreadsheet.Tests.csproj Updated configuration for embedded resources and compilation settings for test resources.
src/.../OpenXmlSpreadsheetGeneratorTests.cs Added a test method for creating spreadsheets with localized column names.
src/.../SampleExportRecord.cs Introduced LocalizedSampleExportRecord class with a localized RecordTitle property.
src/.../TestResources.Designer.cs Added a strongly-typed resource class for accessing localized strings.
src/.../TestResources.cs-CZ.resx Added localized resource strings for the Czech language.
src/.../TestResources.resx Introduced XML content defining schema and resource headers for test resources.
src/.../SpreadsheetColumnAttribute.cs Added properties ResourceFileType and ResourceKey for localization in SpreadsheetColumnAttribute.
src/.../TypeDiscoverer.cs Implemented ResourceManager usage to retrieve localized strings based on new properties.

🐇✨
In code, we weave a tale so bright,
Locales now in every byte.
Columns speak in tongues anew,
Czech and more, a global view.
With tests and strings, we pave the way,
For spreadsheets that know what to say.
🌐📊


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Out of diff range and nitpick comments (1)
src/NetCore.Utilities.Spreadsheet/SpreadsheetColumnAttribute.cs (1)

Line range hint 22-22: Add XML documentation for the formula parameter in the constructor to match other parameters.

+ /// <param name="formula">Sets the formula for the column.</param>
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between fa422ba and c3c48c6.
Files selected for processing (8)
  • src/NetCore.Utilities.Spreadsheet.Tests/NetCore.Utilities.Spreadsheet.Tests.csproj (1 hunks)
  • src/NetCore.Utilities.Spreadsheet.Tests/OpenXmlSpreadsheetGeneratorTests.cs (2 hunks)
  • src/NetCore.Utilities.Spreadsheet.Tests/SampleExportRecord.cs (1 hunks)
  • src/NetCore.Utilities.Spreadsheet.Tests/TestResources.Designer.cs (1 hunks)
  • src/NetCore.Utilities.Spreadsheet.Tests/TestResources.cs-CZ.resx (1 hunks)
  • src/NetCore.Utilities.Spreadsheet.Tests/TestResources.resx (1 hunks)
  • src/NetCore.Utilities.Spreadsheet/SpreadsheetColumnAttribute.cs (1 hunks)
  • src/NetCore.Utilities.Spreadsheet/TypeDiscoverer.cs (2 hunks)
Files skipped from review due to trivial changes (3)
  • src/NetCore.Utilities.Spreadsheet.Tests/TestResources.Designer.cs
  • src/NetCore.Utilities.Spreadsheet.Tests/TestResources.cs-CZ.resx
  • src/NetCore.Utilities.Spreadsheet.Tests/TestResources.resx
Additional Context Used
GitHub Check Runs (1)
Validate Build success (7)

src/NetCore.Utilities.Spreadsheet/SpreadsheetColumnAttribute.cs: [warning] 22-22:
Parameter 'formula' has no matching param tag in the XML comment for 'SpreadsheetColumnAttribute.SpreadsheetColumnAttribute(string, float, bool, string, string)' (but other parameters do)


src/NetCore.Utilities.Spreadsheet/SpreadsheetColumnAttribute.cs: [warning] 22-22:
Parameter 'formula' has no matching param tag in the XML comment for 'SpreadsheetColumnAttribute.SpreadsheetColumnAttribute(string, float, bool, string, string)' (but other parameters do)

Additional comments not posted (5)
src/NetCore.Utilities.Spreadsheet.Tests/NetCore.Utilities.Spreadsheet.Tests.csproj (2)

32-41: The configuration for embedded resources is correctly set up for localization support.


43-49: The compilation settings for TestResources.Designer.cs are correctly configured to ensure proper association with TestResources.resx.

src/NetCore.Utilities.Spreadsheet/SpreadsheetColumnAttribute.cs (2)

57-57: The ResourceFileType property is correctly implemented to support localization.


62-62: The ResourceKey property is correctly implemented to support localization.

src/NetCore.Utilities.Spreadsheet.Tests/SampleExportRecord.cs (1)

121-125: The LocalizedSampleExportRecord class is correctly implemented to test the localization functionality using the new properties.

Comment on lines +54 to +58
if (sca.ResourceFileType != null && string.IsNullOrWhiteSpace(sca.ResourceKey) == false)
{
ResourceManager rm = new(sca.ResourceFileType);
propName = rm.GetString(sca.ResourceKey) ?? propName;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation for retrieving localized property names using ResourceManager is robust. Consider adding error handling for potential exceptions from ResourceManager.GetString.

+ try
+ {
+     propName = rm.GetString(sca.ResourceKey) ?? propName;
+ }
+ catch (Exception ex)
+ {
+     // Handle exception (e.g., log it)
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if (sca.ResourceFileType != null && string.IsNullOrWhiteSpace(sca.ResourceKey) == false)
{
ResourceManager rm = new(sca.ResourceFileType);
propName = rm.GetString(sca.ResourceKey) ?? propName;
}
if (sca.ResourceFileType != null && string.IsNullOrWhiteSpace(sca.ResourceKey) == false)
{
ResourceManager rm = new(sca.ResourceFileType);
try
{
propName = rm.GetString(sca.ResourceKey) ?? propName;
}
catch (Exception ex)
{
// Handle exception (e.g., log it)
}
}

Comment on lines +114 to +139
[Fact]
public void CreateSheet_With_Localized_ColumnName()
{
var configuration = new SpreadsheetConfiguration<LocalizedSampleExportRecord>
{
WorksheetName = "TestSheet",
ExportData = new List<LocalizedSampleExportRecord>()
{
new()
{
RecordTitle = "test record"
}
}
};

CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo("cs-CZ");

using var ms = new MemoryStream();
var result = _spreadsheetGenerator.CreateSingleSheetSpreadsheet(ms, configuration);

// ms.Seek(0, SeekOrigin.Begin);
// File.WriteAllBytes(@"d:\dcore\test.xlsx", ms.ToArray());

result.Should().BeTrue();
ms.Should().NotHaveLength(0);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test method CreateSheet_With_Localized_ColumnName is well-implemented for generating a spreadsheet with a localized column name. Consider adding a verification step to ensure that the column names are correctly localized in the resulting file.

Would you like assistance in implementing this verification step?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for column name localization
2 participants