Values in the .xml file for localization are not reliably appearing in the Blazor views. For example, we have two values in the XML:
<text name="FreePlan">Free Plan</text> <text name="UpgradePlan">Upgrade Plan</text>
FreePlan resolved to Free Plan properly. However, UpgradePlan always returns as the key name "UpgradePlan" instead of the value "Upgrade Plan". I've stepped through your code, and the value isn't even in the dictionary. It doesn't matter where I put the UpgradePlan in the file - it is ignored. We have similar issues with other keys. There are no duplicate keys.
Example razor:
<div>
<span class="btn bg-keyLime me-3 fs-hg-sl-b13 fw-medium text-gray-900 border border-keyLime-active border-dashed px-4">@L("FreePlan")</span>
<NavLink href="/GetFullAccess" class="btn btn-primary fw-medium fs-hg-sl-b13 px-4" role="button">@L("UpgradePlan") <i class="icon-left-arrow float-end text-white ms-3"></i></NavLink>
</div>
I've verified the XML is correct. The code is correct as well:
Even more strange, if I change key "FreePlan"'s text value to "Free Plan 123", it still shows "Free Plan" in the app. Even after an uninstall, clean, bin/obj wipe, and so forth.
WHERE are the values coming from, please? Why are values seemingly not being read from the local XML?
This is blocking releasing an app because we can't localize.
Thanks for any help you can provide.
2 Answer(s)
-
0
The more I think about it - is all of this information stored on the ABP web/API?
If so, which I'm guessing it may be, can you make it local? Requiring a new web/API deployment for every app release seems unnecessary.
Thanks!
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi @JeffMH
ASP.NET Zero uses a database driven approach to manage localization texts. This allows you to change texts while the application is running without needing to recompile or redeploy.
Initial Seeding: The
.xmlfiles in your solution's.Coreproject act as a source only when the application runs for the first time or when a new key is introduced. The system reads the keys from the XML and inserts them into theAbpLanguageTextstable in the database.The Database Takes Precedence: Once a key (like
FreePlan) has been written to the database, the application no longer consults the XML file for that key. The value is always read directly from the database. This explains why changing the value ofFreePlanto "Free Plan 123" in your XML file had no effect. The application continued to use the existing value from the database.How the Blazor Client Gets the Data: When the Blazor application starts, it makes a single API call to the backend to fetch all the necessary localization texts for the current user's language. These texts are then cached in memory on the Blazor client side. When you call
L("UpgradePlan"), it looks for the key in this in memory cache. Since theUpgradePlankey was never added to the database, it's not present in the cache, and the method returns the key itself as a fallback.
<br/> <br/> How to Fix the Issue and the Correct Workflow
The correct way to add a new localization key is to add it to the relevant XML file in your backend solution. This file is typically located in the
Localization/MyProjectNamefolder of yourYourProjectName.Coreproject.Example:
MyProjectName.xml<text name="FreePlan">Free Plan</text> <text name="UpgradePlan">Upgrade Plan</text>Update the Database
After adding the new key to the XML file, you must get it into the database.
- Run your backend project. When the application starts, ABP's seeding mechanism will scan the XML files and add any new keys that are not already in the
AbpLanguageTextstable.
Edit Texts from the Admin UI
Now that your new key is in the database, you should use the application's admin interface not the XML file to manage its value or add translations for other languages.
- Log in to your application as an
adminuser. - Navigate to Administration > Languages.
- Click the Change Texts or Details button next to the language you want to edit.
- In the list, find your newly added key,
UpgradePlan. Its value will likely be empty. Enter the desired text "Upgrade Plan" here and save. - If you want to change the value of an existing key, you must also do it from this interface.
When you restart or refresh your Blazor application, it will fetch the updated values from the API, and
L("UpgradePlan")will correctly resolve to "Upgrade Plan". <br/> <br/> The Advantage of Centralized LocalizationYour comment, "Requiring a new web/API deployment for every app release seems unnecessary," is a very valid point. However, there is a powerful reason why ASP.NET Zero chose this architecture: Agility.
With this centralized system:
- You do not need to recompile and resubmit your Blazor, Angular, or mobile apps to the app stores just to fix a typo in the UI text.
- You simply update the text in the admin panel, and all clients will fetch the correct text the next time they start.
- A non technical person, like a translator or a product manager, can update texts without ever touching the code or dealing with deployments.
This provides a significant administrative advantage, especially for multi language and multi platform applications. Therefore, embracing this intended workflow is generally more efficient in the long run.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)