cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Select the data language with the REST API

oguimard
Retired
query user {
  personSystem(filter:{name:"Thomas"}) {
    id
    name
    dataLanguage {
      ...on Language {
        language:languageCode
        languageId:id
        languageName:name
      }      
    }
  }
}


In HOPEX the data can be inputted in different languages ( English, French, Spanish, Italian, German...). When connected by the GraphQL REST API it is possible to select the data language.

 

Query data in the current data language

 

By default all the queries are performed in the current data language.

 

  • For instance the following query will return the name of the application in English.
Query Result
query app {
  application {
  name
  }
}



{
  "data": {
    "application": [
      { "name": "AA" },
      { "name": "Account Management" }
    ]
  }
}

 

  • To know the current language execute the following query :

 

Query Result
query currentLanguage {
  _currentContext {
    language
    languageId
    languageName
  }
}


{
  "data": {
    "_currentContext": {
      "language": "EN",
      "languageId": "00(6wlHmk400",
      "languageName": "English"
    }
  }
}

 

Query data in a selected data language

 

When requesting the data you can force the language of the return data for all translatable fields (name, comment...). The selection of the language is done by its code : EN, DE, JA, FR, ES, NL, IT... 

 

In one query you can get the data in a given language or several languages.

  • For instance the query below will return the name of the application in English, French and Italian. As they can be only one field with name we create alias of the name. As seen in the example the translation may not be available and an empty string is returned.

 

Query Result
query app {
  application {
  name(language:EN)
  nameFR:name(language:FR)
  nameIT:name(language:IT) 
  }
}





{
  "data": {
    "application": [
      { "name": "Management", "nameFR": "Management", "nameIT": "" },
      { "name": "Account Payable", "nameFR": "", "nameIT": "" },
      { "name": "Account", "nameFR": "Comptabilité", "nameIT": "Conto" }
    ]
  }
}

 

Theses request do not change the default language of the user. Any next query done without defining the language is returned in the default language. 

 

Change the current data language

 

To change the current data language you need to update the user context. For that you need to execute a graphQL mutation on the context.

 

  • In the example below the context will be changed to French.

 

Query Result
mutation updateLanguage {
  _updateCurrentContext(
    currentContext:{
    	language:FR
  		}
  	) 
  { language }
}
{
  "data": {
    "_updateCurrentContext": {
      "language": "FR"
    }
  }
}

 

Change data language for a given user

 

Aside from the current user it is also possible to update the data language of group of user.

 

Query to know the language of a given user

You can query the user to understand which language they have by default. If the return value is blank the default language is the same as the installation.

 

Query Result
query user {
  personSystem(filter:{name:"Thomas"}) {
    id
    name
    dataLanguage {
      ...on Language {
        language:languageCode
      }      
      languageId:id
      languageName:name
    }
  }
}


{
  "data": {
    "personSystem": [
      {
        "id": "qqcxS(UhHzHC",
        "name": "Thomas",
        "dataLanguage": {
          "language": "EN",
          "languageId": "00(6wlHmk400",
          "languageName": "English"
        }
      }
    ]
  }
}

 

Mutation to update the language of a given user

You can set the language of a given user by it's ID.

 

Query Result
mutation updateUser {
updatePersonSystem(
  id:"qqcxS(UhHzHC"
  idType:INTERNAL
  personSystem:{
    dataLanguageCode:FR
  }
  
) {
  dataLanguage {
      ...on Language {
        language:languageCode
      }      
      languageId:id
      languageName:name
    }  } }  

 

Get the list of available data language

To know the possible value of the language code available you can query graphQL.

 

 

 

query availableLanguage {
  language(filter:{id:"I9o3by0knG00"}) {
    language_SpecializedLanguage {
      language:languageCode
      languageId:id
      languageName:name
    }      
  }
}

 

 

 

You may have to to it on the MetaModel schema so that query can work.

 

How to add data language and see them in the API

 

The list of available data language depends on the options defined in HOPEX. Check the available language in the installation options or environment options :

language.png

 

For more details on how to add data language read the full documentation here :

https://doc.mega.com/hopex-v3-en/#page/HOPEX%2FRepositoryBasics.Using_HOPEX_in_a_Multilingual_Contex...

 

 

0 Replies