LocaleModel
LocaleModel
LocaleModel holds the details of a language that the Create and Update methods of Locale send.
When to Use This Class: Use this class to add a language to a stack, or to change the display name or fallback language of one.
Conceptual Role: Acts as the request body of Locale.Create and Locale.Update and their async forms. The SDK sends it inside a locale key.
Returns: LocaleModel. The details of one language.
Class-Level Notes
What the API needs.
- The Content Management API reference asks for the language name and code when you add a language, and accepts a fallback language in the same body. See Add a language.
- FallbackLocale names the language the API falls back to. See Set a fallback language.
Serialization.
- A property you leave null stays out of the request body, so an update with only Name set does not send a code or a fallback language.
Properties
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| Name | string? | No | null | Display name of the language. Serialized as name. |
| Code | string? | No | null | Language code, such as fr-fr. Serialized as code. |
| FallbackLocale | string? | No | null | Code of the fallback language. Serialized as fallback_locale. |
Method Index
LocaleModel has no methods. Set its properties and pass it to the methods named above.
Class-Level Snippet
The snippet below adds the fr-ca language with fr-fr as its fallback language.
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
LocaleModel model = new LocaleModel()
{
Name = "French - Canada",
Code = "fr-ca",
FallbackLocale = "fr-fr"
};
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Locale().Create(model);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}