Getting localized content

Localization in Kentico Kontent allows you to define multiple languages for your project and create culture-specific content. For more information about working with languages, see Localization in Kentico Kontent.

Table of contents

    In this tutorial, you'll learn how to:

    • Choose a URL pattern for your app
    • Get items in a specific language
    • Get item by its localized URL slug
    • Ignore language fallbacks 

    Choosing a URL pattern

    When developing multilingual web apps, it is a good practice to ensure unique URL addresses for each page. One approach is to use language prefixes in URLs, such as en-us or es-es, to differentiate between content cultures. For example, the URLs can be https://myapp.com/en-us/home for English language and https://myapp.com/es-es/home for Spanish language. To retrieve content items in a specific language, see Getting localized content items.

    A worked example

    See an example of adding multi-lingual support to a .NET Core MVC application in a blog post on Working with Localization in Kentico Cloud.

    You can also combine the language prefixes with localized names of your content items. That is, using localized URL slugs. For example, a URL slug of the Home content item translated to Spanish is inicio. In this case, the URL for the Home content item in Spanish language translates to https://myapp.com/es-es/inicio. If you need to retrieve content items by their URL slug value, see Getting items with a specific URL slug.

    Project languages

    Each language in your Kentico Kontent project is uniquely identified by its codename. This codename can be any string you choose, such as, englishen-US, or en-GB.

    Default language

    All Kentico Kontent projects contain a single default language that cannot be removed. When getting content without specifying a language, the Delivery API returns content in the default language.

    Getting localized content items

    To get localized content, specify the language query string and provide the codename of the requested language. For example, in order to get the On Roasts article in Spanish language, you can retrieve a content item like this /items/on_roasts?language=es-ES.

    • Java
    import com.kenticocloud.delivery_core.*; import com.kenticocloud.delivery_rx.*; import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Function; // Prepares an array to hold strongly-typed models List<TypeResolver<?>> typeResolvers = new ArrayList<>(); // Registers the type resolver for articles typeResolvers.add(new TypeResolver<>(Article.TYPE, new Function<Void, Article>() { @Override public Article apply(Void input) { return new Article(); } })); // Prepares the DeliveryService configuration object String projectId = "975bf280-fd91-488c-994c-2f04416e5ee3"; IDeliveryConfig config = DeliveryConfig.newConfig(projectId) .withTypeResolvers(typeResolvers); // Initializes a DeliveryService for Java projects IDeliveryService deliveryService = new DeliveryService(config); // Gets the Spanish variant of an article using a simple request Article article = deliveryService.<Article>item("on_roasts") .languageParameter("es-ES") .get() .getItem(); // Gets the Spanish variant of an article using RxJava2 deliveryService.<Article>item("on_roasts") .languageParameter("es-ES") .getObservable() .subscribe(new Observer<DeliveryItemResponse<Article>>() { @Override public void onSubscribe(Disposable d) { } @Override public void onNext(DeliveryItemResponse<Article> response) { // Gets the article Article article = response.getItem(); } @Override public void onError(Throwable e) { } @Override public void onComplete() { } });
    import com.kenticocloud.delivery_core.*; import com.kenticocloud.delivery_rx.*; import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Function; // Prepares an array to hold strongly-typed models List<TypeResolver<?>> typeResolvers = new ArrayList<>(); // Registers the type resolver for articles typeResolvers.add(new TypeResolver<>(Article.TYPE, new Function<Void, Article>() { @Override public Article apply(Void input) { return new Article(); } })); // Prepares the DeliveryService configuration object String projectId = "975bf280-fd91-488c-994c-2f04416e5ee3"; IDeliveryConfig config = DeliveryConfig.newConfig(projectId) .withTypeResolvers(typeResolvers); // Initializes a DeliveryService for Java projects IDeliveryService deliveryService = new DeliveryService(config); // Gets the Spanish variant of an article using a simple request Article article = deliveryService.<Article>item("on_roasts") .languageParameter("es-ES") .get() .getItem(); // Gets the Spanish variant of an article using RxJava2 deliveryService.<Article>item("on_roasts") .languageParameter("es-ES") .getObservable() .subscribe(new Observer<DeliveryItemResponse<Article>>() { @Override public void onSubscribe(Disposable d) { } @Override public void onNext(DeliveryItemResponse<Article> response) { // Gets the article Article article = response.getItem(); } @Override public void onError(Throwable e) { } @Override public void onComplete() { } });
    • Swift
    import KenticoCloud let client = DeliveryClient.init(projectId: "975bf280-fd91-488c-994c-2f04416e5ee3") // More about strongly-typed models https://github.com/Kentico/cloud-sdk-swift#using-strongly-typed-models client.getItem(modelType: Article.self, itemName: "on_roasts", language: "es-ES") { (isSuccess, itemResponse, error) in if isSuccess { if let article = itemResponse?.item { // Use your item here } } else { if let error = error { print(error) } } }
    import KenticoCloud let client = DeliveryClient.init(projectId: "975bf280-fd91-488c-994c-2f04416e5ee3") // More about strongly-typed models https://github.com/Kentico/cloud-sdk-swift#using-strongly-typed-models client.getItem(modelType: Article.self, itemName: "on_roasts", language: "es-ES") { (isSuccess, itemResponse, error) in if isSuccess { if let article = itemResponse?.item { // Use your item here } } else { if let error = error { print(error) } } }
    • Java
    import com.kenticocloud.delivery; DeliveryClient client = new DeliveryClient("975bf280-fd91-488c-994c-2f04416e5ee3"); List<NameValuePair> params = DeliveryParameterBuilder.params().language("es-ES").build(); // Create strongly typed models according to https://docs.kontent.ai/strongly-typed-models ArticleItem item = client.getItem("on_roasts", ArticleItem.class, params);
    import com.kenticocloud.delivery; DeliveryClient client = new DeliveryClient("975bf280-fd91-488c-994c-2f04416e5ee3"); List<NameValuePair> params = DeliveryParameterBuilder.params().language("es-ES").build(); // Create strongly typed models according to https://docs.kontent.ai/strongly-typed-models ArticleItem item = client.getItem("on_roasts", ArticleItem.class, params);
    • JavaScript
    const KontentDelivery = require("@kentico/kontent-delivery"); // Create strongly typed models according to https://docs.kontent.ai/strongly-typed-models class Article extends KontentDelivery.ContentItem { constructor() { super(); } } const deliveryClient = new KontentDelivery.DeliveryClient({ projectId: "975bf280-fd91-488c-994c-2f04416e5ee3", typeResolvers: [ new KontentDelivery.TypeResolver("article", (rawData) => new Article) ] }); deliveryClient.item("on_roasts") .languageParameter("es-ES") .toObservable() .subscribe(response => console.log(response.item));
    const KontentDelivery = require("@kentico/kontent-delivery"); // Create strongly typed models according to https://docs.kontent.ai/strongly-typed-models class Article extends KontentDelivery.ContentItem { constructor() { super(); } } const deliveryClient = new KontentDelivery.DeliveryClient({ projectId: "975bf280-fd91-488c-994c-2f04416e5ee3", typeResolvers: [ new KontentDelivery.TypeResolver("article", (rawData) => new Article) ] }); deliveryClient.item("on_roasts") .languageParameter("es-ES") .toObservable() .subscribe(response => console.log(response.item));
    • C#
    using Kentico.Kontent.Delivery; // Initializes a content delivery client IDeliveryClient client = DeliveryClientBuilder .WithProjectId("975bf280-fd91-488c-994c-2f04416e5ee3") .Build(); // Gets an article in Spanish // Create strongly typed models according to https://docs.kontent.ai/strongly-typed-models DeliveryItemResponse<Article> response = await client.GetItemAsync<Article>("on_roasts", new LanguageParameter("es-ES") ); ContentItem item = response.Item;
    using Kentico.Kontent.Delivery; // Initializes a content delivery client IDeliveryClient client = DeliveryClientBuilder .WithProjectId("975bf280-fd91-488c-994c-2f04416e5ee3") .Build(); // Gets an article in Spanish // Create strongly typed models according to https://docs.kontent.ai/strongly-typed-models DeliveryItemResponse<Article> response = await client.GetItemAsync<Article>("on_roasts", new LanguageParameter("es-ES") ); ContentItem item = response.Item;
    • PHP
    <?php // Defined by Composer to include required libraries require __DIR__ . "/vendor/autoload.php"; use Kentico\Kontent\Delivery\DeliveryClient; use Kentico\Kontent\Delivery\QueryParams; $client = new DeliveryClient("975bf280-fd91-488c-994c-2f04416e5ee3"); $items = client->getItem("on_roasts", (new QueryParams()) ->language("es-ES"));
    <?php // Defined by Composer to include required libraries require __DIR__ . "/vendor/autoload.php"; use Kentico\Kontent\Delivery\DeliveryClient; use Kentico\Kontent\Delivery\QueryParams; $client = new DeliveryClient("975bf280-fd91-488c-994c-2f04416e5ee3"); $items = client->getItem("on_roasts", (new QueryParams()) ->language("es-ES"));
    • cURL
    curl --request GET \ --url "https://deliver.kontent.ai/975bf280-fd91-488c-994c-2f04416e5ee3/items/on_roasts?language=es-ES" \ --header "content-type: application/json"
    curl --request GET \ --url "https://deliver.kontent.ai/975bf280-fd91-488c-994c-2f04416e5ee3/items/on_roasts?language=es-ES" \ --header "content-type: application/json"
    • Ruby
    require "delivery-sdk-ruby" delivery_client = Kentico::Kontent::Delivery::DeliveryClient.new project_id: "975bf280-fd91-488c-994c-2f04416e5ee3" delivery_client.item("on_roasts") .language("es-ES") .execute do |response| item = response.item end
    require "delivery-sdk-ruby" delivery_client = Kentico::Kontent::Delivery::DeliveryClient.new project_id: "975bf280-fd91-488c-994c-2f04416e5ee3" delivery_client.item("on_roasts") .language("es-ES") .execute do |response| item = response.item end
    • TypeScript
    import { ContentItem, DeliveryClient, Elements, TypeResolver } from "@kentico/kontent-delivery"; // Create strongly typed models according to https://docs.kontent.ai/strongly-typed-models export class Article extends ContentItem { public title: Elements.TextElement; public summary: Elements.TextElement; public post_date: Elements.DateTimeElement; public teaser_image: Elements.AssetsElement; public related_articles: Article[]; } const deliveryClient = new DeliveryClient({ projectId: "975bf280-fd91-488c-994c-2f04416e5ee3", typeResolvers: [ new TypeResolver("article", (rawData) => new Article) ] }); deliveryClient.item<Article>("on_roasts") .languageParameter("es-ES") .toObservable() .subscribe(response => console.log(response.item));
    import { ContentItem, DeliveryClient, Elements, TypeResolver } from "@kentico/kontent-delivery"; // Create strongly typed models according to https://docs.kontent.ai/strongly-typed-models export class Article extends ContentItem { public title: Elements.TextElement; public summary: Elements.TextElement; public post_date: Elements.DateTimeElement; public teaser_image: Elements.AssetsElement; public related_articles: Article[]; } const deliveryClient = new DeliveryClient({ projectId: "975bf280-fd91-488c-994c-2f04416e5ee3", typeResolvers: [ new TypeResolver("article", (rawData) => new Article) ] }); deliveryClient.item<Article>("on_roasts") .languageParameter("es-ES") .toObservable() .subscribe(response => console.log(response.item));

    If the specified content item does not exist in the requested language, the Delivery API checks whether the content is present in the fallback language configured for the requested language. In case the query does not match any content, the API returns a 404 error response.

    Getting items by localized URL slug

    Depending on how you implement routing in your app, you might want to request content items based on the knowledge of their URL slugs.

    To retrieve a content item that is specified by a localized URL slug, you need to call the List content items endpoint and apply appropriate filtering parameters.

    For example, in order to get a Home content item whose URL slug in Spanish is inicio, you can use a query like this /items?language=es-ES&system.type=home&elements.url_pattern=inicio.

    Here's what the query strings do:

    • language=es-ES – specifies the codename of the requested language.
    • system.type=home – filters content items by their content type.
    • elements.url_pattern=inicio – filters content items by a value of a specific content element.
    • Java
    import com.kenticocloud.delivery_core.*; import com.kenticocloud.delivery_rx.*; import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Function; // Prepares an array to hold strongly-typed models List<TypeResolver<?>> typeResolvers = new ArrayList<>(); // Registers the type resolver for articles typeResolvers.add(new TypeResolver<>(Home.TYPE, new Function<Void, Home>() { @Override public Home apply(Void input) { return new Home(); } })); // Prepares the DeliveryService configuration object String projectId = "975bf280-fd91-488c-994c-2f04416e5ee3"; IDeliveryConfig config = DeliveryConfig.newConfig(projectId) .withTypeResolvers(typeResolvers); // Initializes a DeliveryService for Java projects IDeliveryService deliveryService = new DeliveryService(config); // Gets the Spanish variant of a Home content item that has "inicio" in its "URL pattern" element using a simple request List<Home> home = deliveryService.<Home>items() .languageParameter("es-ES") .equalsFilter("system.type", "home") .equalsFilter("elements.url_pattern", "inicio") .get() .getItems(); // Gets the Spanish variant of a Home content item that has "inicio" in its "URL pattern" element using RxJava2 deliveryService.<Home>items() .languageParameter("es-ES") .equalsFilter("system.type", "home") .equalsFilter("elements.url_pattern", "inicio") .getObservable() .subscribe(new Observer<DeliveryItemListingResponse<Home>>() { @Override public void onSubscribe(Disposable d) { } @Override public void onNext(DeliveryItemResponse<Home> response) { // Gets the content items Home item = response.getItem(); } @Override public void onError(Throwable e) { } @Override public void onComplete() { } });
    import com.kenticocloud.delivery_core.*; import com.kenticocloud.delivery_rx.*; import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Function; // Prepares an array to hold strongly-typed models List<TypeResolver<?>> typeResolvers = new ArrayList<>(); // Registers the type resolver for articles typeResolvers.add(new TypeResolver<>(Home.TYPE, new Function<Void, Home>() { @Override public Home apply(Void input) { return new Home(); } })); // Prepares the DeliveryService configuration object String projectId = "975bf280-fd91-488c-994c-2f04416e5ee3"; IDeliveryConfig config = DeliveryConfig.newConfig(projectId) .withTypeResolvers(typeResolvers); // Initializes a DeliveryService for Java projects IDeliveryService deliveryService = new DeliveryService(config); // Gets the Spanish variant of a Home content item that has "inicio" in its "URL pattern" element using a simple request List<Home> home = deliveryService.<Home>items() .languageParameter("es-ES") .equalsFilter("system.type", "home") .equalsFilter("elements.url_pattern", "inicio") .get() .getItems(); // Gets the Spanish variant of a Home content item that has "inicio" in its "URL pattern" element using RxJava2 deliveryService.<Home>items() .languageParameter("es-ES") .equalsFilter("system.type", "home") .equalsFilter("elements.url_pattern", "inicio") .getObservable() .subscribe(new Observer<DeliveryItemListingResponse<Home>>() { @Override public void onSubscribe(Disposable d) { } @Override public void onNext(DeliveryItemResponse<Home> response) { // Gets the content items Home item = response.getItem(); } @Override public void onError(Throwable e) { } @Override public void onComplete() { } });
    • Swift
    import KenticoCloud let client = DeliveryClient.init(projectId:"975bf280-fd91-488c-994c-2f04416e5ee3") let customQuery = "items?language=es-ES&system.type=home&elements.url_pattern=inicio" // More about strongly-typed models https://github.com/Kentico/cloud-sdk-swift#using-strongly-typed-models client.getItems(modelType: Home.self, customQuery: customQuery) { (isSuccess, itemsResponse, error) in if isSuccess { if let items = itemsResponse?.items { // Use your items here } } else { if let error = error { print(error) } }
    import KenticoCloud let client = DeliveryClient.init(projectId:"975bf280-fd91-488c-994c-2f04416e5ee3") let customQuery = "items?language=es-ES&system.type=home&elements.url_pattern=inicio" // More about strongly-typed models https://github.com/Kentico/cloud-sdk-swift#using-strongly-typed-models client.getItems(modelType: Home.self, customQuery: customQuery) { (isSuccess, itemsResponse, error) in if isSuccess { if let items = itemsResponse?.items { // Use your items here } } else { if let error = error { print(error) } }
    • Java
    import com.kenticocloud.delivery; DeliveryClient client = new DeliveryClient("975bf280-fd91-488c-994c-2f04416e5ee3"); List<NameValuePair> params = DeliveryParameterBuilder.params() .language("es-ES") .filterEquals("system.type", "home") .filterEquals("elements.url_pattern", "inicio") .build(); // Create strongly typed models according to https://docs.kontent.ai/strongly-typed-models List<HomeItem> items = client.getItems(HomeItem.class, params);
    import com.kenticocloud.delivery; DeliveryClient client = new DeliveryClient("975bf280-fd91-488c-994c-2f04416e5ee3"); List<NameValuePair> params = DeliveryParameterBuilder.params() .language("es-ES") .filterEquals("system.type", "home") .filterEquals("elements.url_pattern", "inicio") .build(); // Create strongly typed models according to https://docs.kontent.ai/strongly-typed-models List<HomeItem> items = client.getItems(HomeItem.class, params);
    • JavaScript
    const KontentDelivery = require("@kentico/kontent-delivery"); // Create strongly typed models according to https://docs.kontent.ai/strongly-typed-models class Home extends KontentDelivery.ContentItem { constructor() { super(); } } const deliveryClient = new KontentDelivery.DeliveryClient({ projectId: "975bf280-fd91-488c-994c-2f04416e5ee3", typeResolvers: [ new KontentDelivery.TypeResolver("home", (rawData) => new Home) ] }); deliveryClient.items("home") .type("home") .languageParameter("es-ES") .depthParameter(0) .equalsFilter("elements.url_pattern", "inicio") .toObservable() .subscribe(response => console.log(response));
    const KontentDelivery = require("@kentico/kontent-delivery"); // Create strongly typed models according to https://docs.kontent.ai/strongly-typed-models class Home extends KontentDelivery.ContentItem { constructor() { super(); } } const deliveryClient = new KontentDelivery.DeliveryClient({ projectId: "975bf280-fd91-488c-994c-2f04416e5ee3", typeResolvers: [ new KontentDelivery.TypeResolver("home", (rawData) => new Home) ] }); deliveryClient.items("home") .type("home") .languageParameter("es-ES") .depthParameter(0) .equalsFilter("elements.url_pattern", "inicio") .toObservable() .subscribe(response => console.log(response));
    • C#
    using Kentico.Kontent.Delivery; // Initializes a content delivery client IDeliveryClient client = DeliveryClientBuilder .WithProjectId("975bf280-fd91-488c-994c-2f04416e5ee3") .Build(); // Gets the Home content item in Spanish based on the item"s URL slug value // Create strongly typed models according to https://docs.kontent.ai/strongly-typed-models DeliveryItemListingResponse<Home> response = await client.GetItemsAsync<Home>( new LanguageParameter("es-ES"), new EqualsFilter("system.type", "home"), new EqualsFilter("elements.url_pattern", "inicio") ); IReadOnlyList<ContentItem> items = response.Items;
    using Kentico.Kontent.Delivery; // Initializes a content delivery client IDeliveryClient client = DeliveryClientBuilder .WithProjectId("975bf280-fd91-488c-994c-2f04416e5ee3") .Build(); // Gets the Home content item in Spanish based on the item"s URL slug value // Create strongly typed models according to https://docs.kontent.ai/strongly-typed-models DeliveryItemListingResponse<Home> response = await client.GetItemsAsync<Home>( new LanguageParameter("es-ES"), new EqualsFilter("system.type", "home"), new EqualsFilter("elements.url_pattern", "inicio") ); IReadOnlyList<ContentItem> items = response.Items;
    • PHP
    <?php // Defined by Composer to include required libraries require __DIR__ . "/vendor/autoload.php"; use Kentico\Kontent\Delivery\DeliveryClient; use Kentico\Kontent\Delivery\QueryParams; $client = new DeliveryClient("975bf280-fd91-488c-994c-2f04416e5ee3"); $items = $client->getItems((new QueryParams()) ->language("es-ES") ->equals("system.type", "home") ->equals("elements.url_pattern", "inicio"));
    <?php // Defined by Composer to include required libraries require __DIR__ . "/vendor/autoload.php"; use Kentico\Kontent\Delivery\DeliveryClient; use Kentico\Kontent\Delivery\QueryParams; $client = new DeliveryClient("975bf280-fd91-488c-994c-2f04416e5ee3"); $items = $client->getItems((new QueryParams()) ->language("es-ES") ->equals("system.type", "home") ->equals("elements.url_pattern", "inicio"));
    • cURL
    curl --request GET \ --url "https://deliver.kontent.ai/975bf280-fd91-488c-994c-2f04416e5ee3/items?language=es-ES&system.type=home&elements.url_pattern=inicio" \ --header "content-type: application/json"
    curl --request GET \ --url "https://deliver.kontent.ai/975bf280-fd91-488c-994c-2f04416e5ee3/items?language=es-ES&system.type=home&elements.url_pattern=inicio" \ --header "content-type: application/json"
    • Ruby
    require "delivery-sdk-ruby" delivery_client = Kentico::Kontent::Delivery::DeliveryClient.new project_id: "975bf280-fd91-488c-994c-2f04416e5ee3" delivery_client.items([ "system.type".eq("home"), "elements.url_pattern".eq("inicio") ]) .language("es-ES") .execute do |response| items = response.items end
    require "delivery-sdk-ruby" delivery_client = Kentico::Kontent::Delivery::DeliveryClient.new project_id: "975bf280-fd91-488c-994c-2f04416e5ee3" delivery_client.items([ "system.type".eq("home"), "elements.url_pattern".eq("inicio") ]) .language("es-ES") .execute do |response| items = response.items end
    • TypeScript
    import { ContentItem, DeliveryClient, Elements, TypeResolver } from "@kentico/kontent-delivery"; // Create strongly typed models according to https://docs.kontent.ai/strongly-typed-models import { Article } from "./models/article"; export class Home extends ContentItem { public url_pattern: Elements.UrlSlugElement; public contact: Elements.TextElement; public articles: Article[]; } const deliveryClient = new DeliveryClient({ projectId: "975bf280-fd91-488c-994c-2f04416e5ee3", typeResolvers: [ new TypeResolver("home", (rawData) => new Home) ] }); deliveryClient.items<Home>() .type("home") .languageParameter("es-ES") .depthParameter(0) .equalsFilter("elements.url_pattern", "inicio") .toObservable() .subscribe(response => console.log(response));
    import { ContentItem, DeliveryClient, Elements, TypeResolver } from "@kentico/kontent-delivery"; // Create strongly typed models according to https://docs.kontent.ai/strongly-typed-models import { Article } from "./models/article"; export class Home extends ContentItem { public url_pattern: Elements.UrlSlugElement; public contact: Elements.TextElement; public articles: Article[]; } const deliveryClient = new DeliveryClient({ projectId: "975bf280-fd91-488c-994c-2f04416e5ee3", typeResolvers: [ new TypeResolver("home", (rawData) => new Home) ] }); deliveryClient.items<Home>() .type("home") .languageParameter("es-ES") .depthParameter(0) .equalsFilter("elements.url_pattern", "inicio") .toObservable() .subscribe(response => console.log(response));

    If the specified query does match any content items, the Delivery API returns an empty response.

    Ignoring language fallbacks

    To ignore language fallbacks and retrieve content items only in the specified language, you can do so by filtering out any content items whose language is different from the requested one. 

    Exceptions to language fallbacks

    When the Delivery API evaluates language fallbacks for content items, it makes exceptions in the following cases:

    • Links to content items in Rich text elements follow language fallbacks independently.
    • Content items used in Rich text and Linked items elements do NOT follow language fallbacks. This means that whenever linked items are not translated to the requested language, they are not included in the response.

    The table below shows what is returned when working with a project with the default project language set as American English en-US and a second language of Spanish es-ES, which falls back to the default language.

    languagesystem.languageReturned language variant
    es-ESnoneContent items are returned in Spanish. If an item is not translated to Spanish, the fallback language is returned en-US.
    es-ESes-ESContent items are returned in Spanish. If an item is not translated to Spanish, it is not returned.
    es-ESen-USContent items are returned in the fallback language of English. If an item is translated to Spanish, it is not returned.
    • language=es-ES – specifies the codename of the requested language.
    • system.language=es-ES – filters content items by their language variant. Content items that are not translated to the specified language are not returned.

    For example, you can retrieve only the Spanish language variants of content items.

    • Java
    import com.kenticocloud.delivery_core.*; import com.kenticocloud.delivery_rx.*; import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Function; // Prepares the DeliveryService configuration object String projectId = "975bf280-fd91-488c-994c-2f04416e5ee3"; IDeliveryConfig config = DeliveryConfig.newConfig(projectId); // Initializes a DeliveryService for Java projects IDeliveryService deliveryService = new DeliveryService(config); // Gets the Spanish variant of all content items (while ignoring language fallbacks) using a simple request List<ContentItem> items = deliveryService.<ContentItem>items() .languageParameter("es-ES") .equalsFilter("system.language", "es-ES") .get() .getItems(); // Gets the Spanish variant of all content items (while ignoring language fallbacks) using RxJava2 deliveryService.<ContentItem>items() .languageParameter("es-ES") .equalsFilter("system.language", "es-ES") .getObservable() .subscribe(new Observer<DeliveryItemListingResponse<ContentItem>>() { @Override public void onSubscribe(Disposable d) { } @Override public void onNext(DeliveryItemResponse<ContentItem> response) { // Gets the content items List<ConentItem> items = response.getItems(); } @Override public void onError(Throwable e) { } @Override public void onComplete() { } });
    import com.kenticocloud.delivery_core.*; import com.kenticocloud.delivery_rx.*; import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Function; // Prepares the DeliveryService configuration object String projectId = "975bf280-fd91-488c-994c-2f04416e5ee3"; IDeliveryConfig config = DeliveryConfig.newConfig(projectId); // Initializes a DeliveryService for Java projects IDeliveryService deliveryService = new DeliveryService(config); // Gets the Spanish variant of all content items (while ignoring language fallbacks) using a simple request List<ContentItem> items = deliveryService.<ContentItem>items() .languageParameter("es-ES") .equalsFilter("system.language", "es-ES") .get() .getItems(); // Gets the Spanish variant of all content items (while ignoring language fallbacks) using RxJava2 deliveryService.<ContentItem>items() .languageParameter("es-ES") .equalsFilter("system.language", "es-ES") .getObservable() .subscribe(new Observer<DeliveryItemListingResponse<ContentItem>>() { @Override public void onSubscribe(Disposable d) { } @Override public void onNext(DeliveryItemResponse<ContentItem> response) { // Gets the content items List<ConentItem> items = response.getItems(); } @Override public void onError(Throwable e) { } @Override public void onComplete() { } });
    • Swift
    import KenticoCloud let client = DeliveryClient.init(projectId:"975bf280-fd91-488c-994c-2f04416e5ee3") let customQuery = "items?language=es-ES&system.language=es-ES" // More about strongly typed models https://github.com/Kentico/cloud-sdk-swift#using-strongly-typed-models client.getItems(modelType: Article.self, customQuery: customQuery) { (isSuccess, itemsResponse, error) in if isSuccess { if let articles = itemsResponse?.items { // Use your items here } } else { if let error = error { print(error) } }
    import KenticoCloud let client = DeliveryClient.init(projectId:"975bf280-fd91-488c-994c-2f04416e5ee3") let customQuery = "items?language=es-ES&system.language=es-ES" // More about strongly typed models https://github.com/Kentico/cloud-sdk-swift#using-strongly-typed-models client.getItems(modelType: Article.self, customQuery: customQuery) { (isSuccess, itemsResponse, error) in if isSuccess { if let articles = itemsResponse?.items { // Use your items here } } else { if let error = error { print(error) } }
    • Java
    import com.kenticocloud.delivery; DeliveryClient client = new DeliveryClient("975bf280-fd91-488c-994c-2f04416e5ee3"); List<NameValuePair> params = DeliveryParameterBuilder.params() .language("es-ES") .filterEquals("system.language", "es-ES") .build(); ContentItemsListingResponse listingResponse = client.getItems();
    import com.kenticocloud.delivery; DeliveryClient client = new DeliveryClient("975bf280-fd91-488c-994c-2f04416e5ee3"); List<NameValuePair> params = DeliveryParameterBuilder.params() .language("es-ES") .filterEquals("system.language", "es-ES") .build(); ContentItemsListingResponse listingResponse = client.getItems();
    • JavaScript
    const KontentDelivery = require("@kentico/kontent-delivery"); const deliveryClient = new KontentDelivery.DeliveryClient({ projectId: "975bf280-fd91-488c-994c-2f04416e5ee3", }); deliveryClient.items() .languageParameter("es-ES") .equalsFilter("system.language", "es-ES") .toObservable() .subscribe(response => console.log(response.items));
    const KontentDelivery = require("@kentico/kontent-delivery"); const deliveryClient = new KontentDelivery.DeliveryClient({ projectId: "975bf280-fd91-488c-994c-2f04416e5ee3", }); deliveryClient.items() .languageParameter("es-ES") .equalsFilter("system.language", "es-ES") .toObservable() .subscribe(response => console.log(response.items));
    • C#
    using Kentico.Kontent.Delivery; // Initializes a content delivery client IDeliveryClient client = DeliveryClientBuilder .WithProjectId("975bf280-fd91-488c-994c-2f04416e5ee3") .Build(); // Gets the Spanish variant of all content items and ignores language fallbacks DeliveryItemListingResponse<object> response = await client.GetItemsAsync<object>( new LanguageParameter("es-ES"), new EqualsParameter("system.language", "es-ES") ); IReadOnlyList<ContentItem> items = response.Items;
    using Kentico.Kontent.Delivery; // Initializes a content delivery client IDeliveryClient client = DeliveryClientBuilder .WithProjectId("975bf280-fd91-488c-994c-2f04416e5ee3") .Build(); // Gets the Spanish variant of all content items and ignores language fallbacks DeliveryItemListingResponse<object> response = await client.GetItemsAsync<object>( new LanguageParameter("es-ES"), new EqualsParameter("system.language", "es-ES") ); IReadOnlyList<ContentItem> items = response.Items;
    • PHP
    <?php // Defined by Composer to include required libraries require __DIR__ . "/vendor/autoload.php"; use Kentico\Kontent\Delivery\DeliveryClient; $client = new DeliveryClient("975bf280-fd91-488c-994c-2f04416e5ee3"); $items = $client->getItems((new QueryParams()) ->language("es-ES") ->equals("system.language", "es-ES"));
    <?php // Defined by Composer to include required libraries require __DIR__ . "/vendor/autoload.php"; use Kentico\Kontent\Delivery\DeliveryClient; $client = new DeliveryClient("975bf280-fd91-488c-994c-2f04416e5ee3"); $items = $client->getItems((new QueryParams()) ->language("es-ES") ->equals("system.language", "es-ES"));
    • cURL
    curl --request GET \ --url "https://deliver.kontent.ai/975bf280-fd91-488c-994c-2f04416e5ee3/items?language=es-ES&system.language=es-ES" \ --header "content-type: application/json"
    curl --request GET \ --url "https://deliver.kontent.ai/975bf280-fd91-488c-994c-2f04416e5ee3/items?language=es-ES&system.language=es-ES" \ --header "content-type: application/json"
    • Ruby
    require "delivery-sdk-ruby" delivery_client = Kentico::Kontent::Delivery::DeliveryClient.new project_id: "975bf280-fd91-488c-994c-2f04416e5ee3" delivery_client.items(["system.language".eq("es-ES")]) .language("es-ES") .execute do |response| items = response.items end
    require "delivery-sdk-ruby" delivery_client = Kentico::Kontent::Delivery::DeliveryClient.new project_id: "975bf280-fd91-488c-994c-2f04416e5ee3" delivery_client.items(["system.language".eq("es-ES")]) .language("es-ES") .execute do |response| items = response.items end
    • TypeScript
    import { ContentItem, DeliveryClient } from "@kentico/kontent-delivery"; const deliveryClient = new DeliveryClient({ projectId: "975bf280-fd91-488c-994c-2f04416e5ee3", }); deliveryClient.items<ContentItem>() .languageParameter("es-ES") .equalsFilter("system.language", "es-ES") .toObservable() .subscribe(response => console.log(response.items));
    import { ContentItem, DeliveryClient } from "@kentico/kontent-delivery"; const deliveryClient = new DeliveryClient({ projectId: "975bf280-fd91-488c-994c-2f04416e5ee3", }); deliveryClient.items<ContentItem>() .languageParameter("es-ES") .equalsFilter("system.language", "es-ES") .toObservable() .subscribe(response => console.log(response.items));

    What's next?

    In this article, you learned how you can handle URLs in multilingual apps and two ways of retrieving translated content. If you know the content item's codename, you can request it directly and specify a language. When you need to request an item by its localized URL slug, use filters to get the item you need.