Show / Hide Table of Contents

Class JsonStringLocalizerFactory

Represents a factory that creates JsonStringLocalizer instances.

JsonStringLocalizer is a replacement of the .resx files system, using .json files instead.

When working with JSON resource files, take into account the following instructions:

  1. Create a folder in your project to hold all JSON resource files. The recommended name for this folder is "Resources".
  2. Create the TypeName class. This is a static class (can be empty) placed in the resources folder. This class will be used to resolve the assembly where resource files are contained, and also to resolve the base file name of your resource files. The Recomended name for this class is "{SomePrefix}Resources.cs". E.g.: "UtilResources.cs".
  3. Create your JSON resources files in your resources folder, you should set them as embedded resources and name those files following these conventions:
    • "TypeName.json"
    • "TypeName-language.json"
    • "TypeName-language-country.json"
    • "TypeName-language-country-region.json"
  4. Resource strings are resolved from most specif to less specific cultures, so if no file for a culture is found, TypeName.json might be used to resolve your strings. The recomendation is to put in this file all your localized strings in "English" language, that way english will be the default resource culture.
  5. A good example of JSON resource files for a project supporting English and Spanish could be as follow:
    • UtilResources.cs
    • UtilResources.json (default culture: english strings)
    • UtilResources-es.json
Inheritance
System.Object
JsonStringLocalizerFactory
Namespace: Celerik.NetCore.Util
Assembly: cs.temp.dll.dll
Syntax
public class JsonStringLocalizerFactory : IStringLocalizerFactory

Constructors

JsonStringLocalizerFactory(String)

Initializes a new instance of the class.

Declaration
public JsonStringLocalizerFactory(string resourcesPath = "Resources")
Parameters
Type Name Description
System.String resourcesPath

The relative path under application root where resource files are located. E.g.: "Resources". By default this is set to "Resources".

Exceptions
Type Condition
System.ArgumentNullException

If resourcesPath is null.

Methods

Create(String, String)

Creates a JsonStringLocalizer using the passed-in baseName and location.

Declaration
public IStringLocalizer Create(string baseName, string location)
Parameters
Type Name Description
System.String baseName

The name of the assembly where JSON resource files are embedded. E.g.: "Celerik.NetCore.Util".

System.String location

The base name of your resource files. E.g.: "UtilResources".

Returns
Type Description
IStringLocalizer

A JsonStringLocalizer built with the passed-in baseName and location.

Exceptions
Type Condition
System.ArgumentNullException

If baseName or location are null or empty.

System.DllNotFoundException

If a .DLL with the provided baseName was not found.

Create(Type)

Creates a JsonStringLocalizer using the Assembly and Name of the specified Type.

Declaration
public IStringLocalizer Create(Type resourceSource)
Parameters
Type Name Description
System.Type resourceSource

The Type of the source resource.

Returns
Type Description
IStringLocalizer

A JsonStringLocalizer built with the passed-in Type.

Exceptions
Type Condition
System.ArgumentNullException

If resourceSource is null.

In This Article
Back to top Generated by DocFX