Locale

View as Markdown

Locale

Locale represents the languages (locales) of a stack. You create and publish entries in each language you add to a stack.

When to Use This Class: Use this class when your code adds a language to a stack, changes its display name or fallback language, or removes it.

Conceptual Role: Acts as the Content Management API client for the /locales endpoint. Call stack.Locale() to get an instance.

Returns: Locale. A handle for language operations.

Instance State

The code you pass to stack.Locale() decides which methods you can call:

  • Call stack.Locale() without a code to work with the collection, for example Query or Create.
  • Call stack.Locale("<LOCALE_CODE>") to work with one language, for example Fetch or Delete.

A method from the other group throws before any request leaves the SDK. Query, Create, and CreateAsync throw InvalidOperationException on an instance with a code. The other methods throw ArgumentException on an instance without one. The Method Index below lists every method in each group.

Warning The SDK checks an empty string as if it were no code, but adds it to the path. stack.Locale("") allows Query and Create, and those requests go to /locales/ with a trailing slash. Pass null, or call stack.Locale() with no argument, when you mean the collection.

Warning Set the code only through stack.Locale("<LOCALE_CODE>"). The instance has a settable Uid property, but the SDK builds the request path when you call stack.Locale(). Setting Uid later changes which methods the SDK allows without changing which language the request targets.

Class-Level Notes

Credentials.

  • stack.Locale() throws InvalidOperationException when the client has no authtoken and the stack has no management token.
  • Fetch, FetchAsync, Delete, DeleteAsync, CreateAsync, and UpdateAsync run the same check again before the request. The synchronous Create and Update do not repeat it.
  • The Content Management API reference accepts a management token or an authtoken for every language request. Pass a management token as the second argument of client.Stack().

The language code is the identifier.

  • The Content Management API identifies a language by its code in the request path, /locales/<LOCALE_CODE>. Pass the code, such as fr-fr, to stack.Locale().

Branch Scoping.

  • The Content Management API manages languages per branch. The branchUid you pass to client.Stack() goes out as the branch header, so every method of this class works on the languages of that branch.
  • Pass include_branch set to true in a ParameterCollection to get the _branch key in the response.

Request bodies.

  • Create and Update send a LocaleModel inside a locale key. A property you leave null stays out of the body.

Query parameters.

  • Every method except Query takes an optional ParameterCollection. The SDK adds each entry to the query string of the request.

Rate Limiting & Retry.

  • This SDK automatically retries on 429 with configurable delay and attempt limits.

Additional Resource For more information on retry settings, refer to the ContentstackClientOptions documentation.

Properties

PropertyTypeAccessDefaultDescription
Uidstring?Read/writeThe argument of stack.Locale()The code the instance targets. Setting it later does not change the request path.

Method Index

The groups below follow the Instance State split.

Work with the collection. Available on stack.Locale() with no code.

Method NameReturnsDescription
QueryA new query for languages.Builds a query that lists languages.
CreateThe API response with the created language.Adds a language to the stack.
CreateAsyncThe API response with the created language.Adds a language asynchronously.

Work with one language. Available on stack.Locale("<LOCALE_CODE>").

Method NameReturnsDescription
FetchThe API response with the requested language.Gets the details of the language.
FetchAsyncThe API response with the requested language.Gets the details asynchronously.
UpdateThe API response with the updated language.Changes the details of the language.
UpdateAsyncThe API response with the updated language.Changes the details asynchronously.
DeleteThe API response with the deletion notice.Removes the language from the stack.
DeleteAsyncThe API response with the deletion notice.Removes the language asynchronously.

Class-Level Snippet

The snippet below adds the fr-ca language with fr-fr as its fallback, fetches it by code, and lists every language with a count.

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;

ContentstackClient client = new ContentstackClient();
Stack stack = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>");

LocaleModel model = new LocaleModel() { Name = "French - Canada", Code = "fr-ca", FallbackLocale = "fr-fr" };

try
{
    ContentstackResponse created = stack.Locale().Create(model);
    Console.WriteLine(created.OpenJsonObjectResponse().ToJsonString());

    ContentstackResponse fetched = stack.Locale("fr-ca").Fetch();
    Console.WriteLine(fetched.OpenJsonObjectResponse().ToJsonString());

    ContentstackResponse all = stack.Locale().Query().IncludeCount().Find();
    Console.WriteLine(all.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

Methods

Each method of the Locale class has its own section below, with its parameters, validation rules, behavior, and examples.

Create

Create adds a language to the stack.

NameTypeDescription
model (required)LocaleModel

Name, code, and fallback language of the new language.

Default: Not applicable
collectionParameterCollection?

Query parameters to add to the request.

Default: null

Returns: ContentstackResponse. The API response with the created language.

Validation

  • Throws InvalidOperationException if the instance has a code, because Create adds a new language to the collection. Call stack.Locale() with no argument.
  • Throws ArgumentNullException if model is null, because the request body holds the model.
  • Throws ContentstackErrorException when the API rejects the request.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends one POST /locales request with the body {"locale": {...}}. See Add a language in the Content Management API reference.
  • Serializes Name, Code, and FallbackLocale as name, code, and fallback_locale. A property you leave null stays out of the body.
  • The Content Management API reference asks for the language name and code in the body, and accepts a fallback language in the same body. You can add a language that Contentstack supports or a custom language.
  • Set FallbackLocale to give the new language a fallback language. See Set a fallback language in the Content Management API reference.
  • Adds each entry of collection to the query string.
  • Returns the raw API response with the created language. To work with it, call stack.Locale("<LOCALE_CODE>") with its code.

Example

Basic usage: add a language

using System;
using System.Collections.Generic;
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 - France", Code = "fr-fr" };

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").Locale().Create(model);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

All parameters: add a language with every model property and a query parameter, using a management token

using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient();

LocaleModel model = new LocaleModel()
{
    Name = "French - Canada",
    Code = "fr-ca",
    FallbackLocale = "fr-fr"
};

ParameterCollection collection = new ParameterCollection();
collection.Add("include_branch", true);

try
{
    ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Locale().Create(model, collection);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

CreateAsync

CreateAsync adds a language to the stack, without blocking the calling thread.

NameTypeDescription
model (required)LocaleModel

Name, code, and fallback language of the new language.

Default: Not applicable
collectionParameterCollection?

Query parameters to add to the request.

Default: null

Returns: Task<ContentstackResponse>. The API response with the created language.

Validation

  • Throws InvalidOperationException if the instance has a code, because Create adds a new language to the collection. Call stack.Locale() with no argument.
  • Throws InvalidOperationException if the client has no authtoken and the stack has no management token.
  • Throws ArgumentNullException if model is null, because the request body holds the model.
  • Throws ContentstackErrorException when the API rejects the request.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Returns a task. The client-side checks above run when you call CreateAsync, before it returns the task. An API rejection surfaces when you await the task.
  • Runs the credential check again before the request. The synchronous Create relies on the check that stack.Locale() ran.
  • Otherwise behaves like Create.

Example

Basic usage: add a language

using System;
using System.Collections.Generic;
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 - France", Code = "fr-fr" };

try
{
    ContentstackResponse response = await client.Stack("<API_KEY>").Locale().CreateAsync(model);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

All parameters: add a language with every model property and a query parameter

using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

LocaleModel model = new LocaleModel()
{
    Name = "French - Canada",
    Code = "fr-ca",
    FallbackLocale = "fr-fr"
};

ParameterCollection collection = new ParameterCollection();
collection.Add("include_branch", true);

try
{
    ContentstackResponse response = await client.Stack("<API_KEY>").Locale().CreateAsync(model, collection);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

Delete

Delete removes the language whose code you passed to stack.Locale() from the stack.

NameTypeDescription
collectionParameterCollection?

Query parameters to add to the request.

Default: null

Returns: ContentstackResponse. The API response with the deletion notice.

Validation

  • Throws InvalidOperationException if the client has no authtoken and the stack has no management token.
  • Throws ArgumentException if the instance has no code, because Delete acts on one language. Call stack.Locale("<LOCALE_CODE>").
  • Throws ContentstackErrorException when the API rejects the request.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends one DELETE /locales/<LOCALE_CODE> request. See Delete language in the Content Management API reference.
  • Adds each entry of collection to the query string.
  • Returns the raw API response with the deletion notice.

Example

Warning Delete removes the language from the stack. Add it again with the Create method if you need it later.

Basic usage: delete a language

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").Locale("<LOCALE_CODE>").Delete();
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

All parameters: delete with a query parameter, using a management token

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient();

ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");

try
{
    ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Locale("<LOCALE_CODE>").Delete(collection);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

DeleteAsync

DeleteAsync removes the language whose code you passed to stack.Locale() from the stack, without blocking the calling thread.

NameTypeDescription
collectionParameterCollection?

Query parameters to add to the request.

Default: null

Returns: Task<ContentstackResponse>. The API response with the deletion notice.

Validation

  • Throws InvalidOperationException if the client has no authtoken and the stack has no management token.
  • Throws ArgumentException if the instance has no code, because Delete acts on one language. Call stack.Locale("<LOCALE_CODE>").
  • Throws ContentstackErrorException when the API rejects the request.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Returns a task. The client-side checks above run when you call DeleteAsync, before it returns the task. An API rejection surfaces when you await the task.
  • Otherwise behaves like Delete.

Example

Warning Delete removes the language from the stack. Add it again with the CreateAsync method if you need it later.

Basic usage: delete a language

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

try
{
    ContentstackResponse response = await client.Stack("<API_KEY>").Locale("<LOCALE_CODE>").DeleteAsync();
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

All parameters: delete with a query parameter

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

ParameterCollection collection = new ParameterCollection();
collection.Add("<PARAMETER_NAME>", "<PARAMETER_VALUE>");

try
{
    ContentstackResponse response = await client.Stack("<API_KEY>").Locale("<LOCALE_CODE>").DeleteAsync(collection);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

Fetch

Fetch gets the details of the language whose code you passed to stack.Locale().

NameTypeDescription
collectionParameterCollection?

Query parameters to add to the request.

Default: null

Returns: ContentstackResponse. The API response with the requested language.

Validation

  • Throws InvalidOperationException if the client has no authtoken and the stack has no management token.
  • Throws ArgumentException if the instance has no code, because Fetch acts on one language. Call stack.Locale("<LOCALE_CODE>").
  • Throws ContentstackErrorException when the API rejects the request.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends one GET /locales/<LOCALE_CODE> request. See Get a language in the Content Management API reference.
  • Adds each entry of collection to the query string.
  • Returns the raw API response with the language. Read the body with OpenJsonObjectResponse().

Example

Basic usage: fetch a language

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").Locale("<LOCALE_CODE>").Fetch();
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

All parameters: fetch with a query parameter, using a management token

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient();

ParameterCollection collection = new ParameterCollection();
collection.Add("include_branch", true);

try
{
    ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Locale("<LOCALE_CODE>").Fetch(collection);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

Edge case: fetch on an instance with no code

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Models;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").Locale().Fetch();
}
catch (ArgumentException e)
{
    // Thrown because stack.Locale() received no code
    Console.WriteLine(e.Message);
}

FetchAsync

FetchAsync gets the details of the language whose code you passed to stack.Locale(), without blocking the calling thread.

NameTypeDescription
collectionParameterCollection?

Query parameters to add to the request.

Default: null

Returns: Task<ContentstackResponse>. The API response with the requested language.

Validation

  • Throws InvalidOperationException if the client has no authtoken and the stack has no management token.
  • Throws ArgumentException if the instance has no code, because Fetch acts on one language. Call stack.Locale("<LOCALE_CODE>").
  • Throws ContentstackErrorException when the API rejects the request.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Returns a task. The client-side checks above run when you call FetchAsync, before it returns the task. An API rejection surfaces when you await the task.
  • Otherwise behaves like Fetch.

Example

Basic usage: fetch a language

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

try
{
    ContentstackResponse response = await client.Stack("<API_KEY>").Locale("<LOCALE_CODE>").FetchAsync();
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

All parameters: fetch with a query parameter

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

ParameterCollection collection = new ParameterCollection();
collection.Add("include_branch", true);

try
{
    ContentstackResponse response = await client.Stack("<API_KEY>").Locale("<LOCALE_CODE>").FetchAsync(collection);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

Query

Query creates a query that lists the languages of the stack.

This method takes no parameters.

Returns: Query. A new query for languages.

Validation

  • Throws InvalidOperationException if the instance has a code, because Query works with the whole collection. Call stack.Locale() with no argument.
  • Errors from the API come from the Find or FindAsync call that follows, not from Query.

Behavior

  • Sends no request. Find or FindAsync on the returned query sends one GET /locales request. See Get all languages in the Content Management API reference.
  • The Content Management API reference lists include_count and include_branch for this request. Chain IncludeCount for the count, and pass include_branch in the ParameterCollection you give to Find.
  • The query keeps every value you add. Create a new query with stack.Locale().Query() for a different request.

Example

Basic usage: list all languages

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").Locale().Query().Find();
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

List languages with a count and extra query parameters, using a management token

using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient();

ParameterCollection collection = new ParameterCollection();
collection.Add("include_branch", true);

try
{
    ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Locale().Query().IncludeCount().Find(collection);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

Update

Update changes the details of the language whose code you passed to stack.Locale().

NameTypeDescription
model (required)LocaleModel

New name or fallback language of the language.

Default: Not applicable
collectionParameterCollection?

Query parameters to add to the request.

Default: null

Returns: ContentstackResponse. The API response with the updated language.

Validation

  • Throws ArgumentException if the instance has no code, because Update acts on one language. Call stack.Locale("<LOCALE_CODE>").
  • Throws ArgumentNullException if model is null, because the request body holds the model.
  • Throws ContentstackErrorException when the API rejects the request.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Sends one PUT /locales/<LOCALE_CODE> request with the body {"locale": {...}}. See Update language in the Content Management API reference.
  • Serializes Name, Code, and FallbackLocale as name, code, and fallback_locale. A property you leave null stays out of the body.
  • The Content Management API reference describes changing the display name and the fallback language of the language. See Update fallback language for the fallback case.
  • Adds each entry of collection to the query string.

Example

Basic usage: update a language

using System;
using System.Collections.Generic;
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" };

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").Locale("<LOCALE_CODE>").Update(model);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

All parameters: update with every model property and a query parameter

using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient();

LocaleModel model = new LocaleModel() { Name = "French", FallbackLocale = "en-us" };

ParameterCollection collection = new ParameterCollection();
collection.Add("include_branch", true);

try
{
    ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Locale("<LOCALE_CODE>").Update(model, collection);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}

UpdateAsync

UpdateAsync changes the details of the language whose code you passed to stack.Locale(), without blocking the calling thread.

NameTypeDescription
model (required)LocaleModel

New name or fallback language of the language.

Default: Not applicable
collectionParameterCollection?

Query parameters to add to the request.

Default: null

Returns: Task<ContentstackResponse>. The API response with the updated language.

Validation

  • Throws InvalidOperationException if the client has no authtoken and the stack has no management token.
  • Throws ArgumentException if the instance has no code, because Update acts on one language. Call stack.Locale("<LOCALE_CODE>").
  • Throws ArgumentNullException if model is null, because the request body holds the model.
  • Throws ContentstackErrorException when the API rejects the request.

Additional Resource Refer to Content Management API Errors for the full error code list.

Behavior

  • Returns a task. The client-side checks above run when you call UpdateAsync, before it returns the task. An API rejection surfaces when you await the task.
  • Runs the credential check again before the request. The synchronous Update relies on the check that stack.Locale() ran.
  • Otherwise behaves like Update.

Example

Basic usage: update a language

using System;
using System.Collections.Generic;
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" };

try
{
    ContentstackResponse response = await client.Stack("<API_KEY>").Locale("<LOCALE_CODE>").UpdateAsync(model);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}

All parameters: update with every model property and a query parameter

using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

LocaleModel model = new LocaleModel() { Name = "French", FallbackLocale = "en-us" };

ParameterCollection collection = new ParameterCollection();
collection.Add("include_branch", true);

try
{
    ContentstackResponse response = await client.Stack("<API_KEY>").Locale("<LOCALE_CODE>").UpdateAsync(model, collection);
    Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
    Console.WriteLine(e.ErrorMessage);
}