abpframework / abpframework/abp

why not work json sub root IStringLocalizer?

Open
#16,615 3 comments 2 reactions 1 assignee View on GitHub

@maliming is already working on this.

Since May 22, 2023.

feature
Dominant language
C#
Stars
14.4k
Forks
3.7k
Avg merge
15h 32m
Merged PRs (30d)
106

Description

It is possible that the JSON sub root is not working due to incorrect configuration or implementation of IStringLocalizer with JSON files. Here are some possible reasons why it may not be working.

file en.json :

{
 "culture": "en",
  "texts": {
   {
     "Order": {
      "Total": "About Us",
      "Product": {
        "Name" : "Mobile",
        "Code" : "Code sku",
      }
    },
    "Home": {
       "Title": "Home Page",
       "Description": "This is the home page."
     }
   }
  }
}
<label>@L["Order.Product.Name"]</label>
<label>@L["Order.Product.Code"]</label>

Error system :
'Can not parse json string. The JSON value could not be converted to System.String. Path: $.texts.Class | LineNumber: 6 | BytePositionInLine: 14.

So please add this code to abp.framework update version next for suport root json keys :
https://codewithmukesh.com/blog/json-based-localization-in-aspnet-core/
Or
https://stackoverflow.com/questions/43615912/asp-net-core-localization-with-json-files

And Sample code in cshtml:

<label>@L["Order.Product.Name"]</label>
<label>@L["Order.Product.Code"]</label>

This work .

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.