Translations
API

Translations API

Introduction

ROQ provides Translation API for easy integration with a custom application or customizes the ROQ's AI generated application.

Queries

translation()

With this method, you can get the translation data based on the translation id. For the GraphQL queries detail, please look into the translation() (opens in a new tab) API documentation.

import { Platform } from '@roq/nodejs'
 
const roqClient = new Platform({
	apiKey: process.env.ROQ_API_KEY,
	environmentId: process.env.ROQ_ENVIRONMENT_ID,
	host: process.env.ROQ_PLATFORM_URL
})
 
const translation = await roqClient.asUser("7877d2d0-dea7-473e-a158-57eca3123906").translation({ 
	id: "8acf421e-2bdc-48e0-9291-42202ac94b6f"
})
ParameterTypeDescription
idstringThe translation id

translations()

This method will return all translations and can be filtered with the filter option. You can look into the translations() (opens in a new tab) API documentation.

const translationsData = await roqClient.asSuperAdmin().translations({
	limit: 1000,
	filter: {
		locale: { equalTo: "de-DE" }
	}
})
 
console.log(translationsData.translations.data.length)
ParameterTypeDescription
limitintegerLimiting the translation result
filterobjectFilter the results
filter:idobjectFilter based on the translation id
filter:localeobjectFilter the results based on locale
filter:translationKeyIdobjectFilter the results based on the translation key id

translationKey()

With this method, you can get the translation key based on its id. For example to find the key for translationKey id 052ee336-af23-487f-bce5-3f8c1fa5a972

const translationKey = await roqClient
.asUser("7877d2d0-dea7-473e-a158-57eca3123906")
.translationKey({
	 id: "052ee336-af23-487f-bce5-3f8c1fa5a972",
	 withTranslations: true 
})
ParameterTypeDescription
idstringThe translation key id
withTranslationsbooleanInclude all the translations

If you set withTranslations parameter to true then you will get all the translations, for instance:

{
	"id": "052ee336-af23-487f-bce5-3f8c1fa5a972",
	"key": "roq-ui.auth.channel-owner.input.company.placeholder",
	"createdAt": "2023-07-07T02:07:36.785Z",
	"updatedAt": "2023-07-07T02:07:36.785Z",
	"translations": {
		"data": [
			{
				"id": "7d259885-e834-4a5b-9153-2ca56ce90a07",
				"locale": "de-DE",
				"value": "Geben Sie Ihr Organization ein",
				"createdAt": "2023-07-07T02:07:36.785Z",
				"updatedAt": "2023-07-07T02:07:37.267Z"
			},
			{
				"id": "8acf421e-2bdc-48e0-9291-42202ac94b6f",
				"locale": "en-US",
				"value": "Enter your Organization",
				"createdAt": "2023-07-07T02:07:36.785Z",
				"updatedAt": "2023-07-07T02:07:37.267Z"
			}
		],
		"totalCount": 2
	}
}

Please read the documentation of the translationKey() (opens in a new tab) API for further detail.

translationKeys()

The translationKeys() can query all the translations included with translation keys. Read the documentation of this API here (opens in a new tab).

const translationKeys = await roqClient.asSuperAdmin()
.translationKeys({
	limit: 3,
	filter: {
		key: { like: "%email%"}
		locale: { equalTo: "de-DE" }
	},
	withTranslations: true
})

With this method you can find a key based on the keyword, for instance, if you want to search for a key that contains the word "email", you can find the key with this filter.

filter: {
	key: { like: "%email%"}
}
ParameterTypeDescription
limitintegerlimiting the translations result
filterobjectfilter the results
filter:idobjectfilter based on the translation id
filter:keyobjectfilter based on the translation key
filter:localeobjectfilter the results based on locale
withTranslationsbooleaninclude the translations on the result queries

Mutations

createTranslationKey()

You can create a translation key using createTranslationKey() (opens in a new tab) API.

const createStatus = await roqClient.asSuperAdmin().createTranslationKey({
	translationKey: {
		key: "com.myapp.title",
		translations: {
			value: "Lokal App",
			locale: "en-US"
		}
	}
})
ParameterTypeDescription
translationKeyobjecttranslation key option
translationKey:keystringtranslation key name
translationKey:translationsobjecttranslation key value and locale

The created key can be checked in the ROQ Console or by using translationKey() API. For instance, creating a translation key com.myapp.title will result:

{
  createTranslationKey: {
    id: 'fb6d4930-9f4b-4fdf-ae0f-c5db5c218f55',
    key: 'com.myapp.title',
    createdAt: '2023-07-25T04:45:25.652Z',
    updatedAt: '2023-07-25T04:45:25.652Z',
    translations: { data: [Array], totalCount: 1 }
  }
}

Then you can use the result id as a parameter for the translationKey() method.

updateTranslationKey()

The updateTranslationKey() (opens in a new tab) API will update the translation based on the translation key. For example to update the translation key com.myapp.title from the previous example:

const update = await roqClient.asSuperAdmin().updateTranslationKey({
	id: "fb6d4930-9f4b-4fdf-ae0f-c5db5c218f55",
	translationKey: {
		translations: [{
			locale: "de-DE",
			value: "Lokale Anwendung"
		}]
	}
})

The code example above will translate the key com.myapp.title into the German language.

ParameterTypeDescription
idstringThe translation key id to be updated
translationKeyobjectThe locale and the translation value. You can update the translation for different locales
translationKey:translationsobject arraythe locales and the translation values

upsertTranslationKeys()

This API will insert the key (if not exist) and will update or insert the translation values. This API can update more than one translation key, please read the documentation of this upsertTranslationKeys() API here (opens in a new tab).

const upsert = await roqClient.asSuperAdmin().upsertTranslationKeys({
	translationKeys: [{
		key: "com.myapp.footer.author",
		translations: [
		{
		    locale: "en-US",
			value: "ROQ"
		}, 
		{
			locale: "de-DE",
			value: "ROQ"
		}]
	}]
})
ParameterTypeDescription
translationKeysobject arraythe translation keys
translationKeys:keystringthe translation key to be created or update the translation values
translationKeys:translationsobject arraythe translation locales and values