Contentful logo

Contentful Community

Locale with Java

How can I get entries for specific Locale using the Java SDK? In want to do like the example

Cat happycat = client

but for a specific locale. Example from this page:

I have declared two locales for my Entry (en-US and sv-SE). When I get the entry I only get en-US and never sv-SE regardless of how I try. Example:

CDAEntry entry = client.fetch(CDAEntry.class).one("..entryId...");
Map<String, Object> rawFields = entry.rawFields();
log.debug("RAW: "+rawFields);

Localizer localize = entry.localize(locale);
log.debug("Localizer for ("+locale+"): "+localize.getField("subject"));

The raw fields debug only shows the en-US locales. Shortened down version below

RAW: {subject={en-US=My text goes here}, .... }

The localizer also only returns English results.

To answer my own question; Locale can be set using the query format with the string value ‘locale’. See example below.

	Email email = client.observeAndTransform(Email.class)
			.where("fields.template[match]", "verify-email")
			.where("locale", "se-SV")