Skip to content

Languages

This article contains all actions for retrieving and managing languages.

Get language by ID#

query {
  getLocaleLanguage(id: "de") {
    id
    label
    status
    mtime
    ctime
    editor
  }
}
const body = JSON.stringify({'query':
`query {
  getLocaleLanguage(id: "de") {
    id
    label
    status
    mtime
    ctime
    editor
  }
}`});

fetch($('.aimeos').data('graphql'), {
    method: 'POST',
    credentials: 'same-origin',
    headers: { // Laravel only
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    },
    body: body
}).then(response => {
    return response.json();
}).then(data => {
    console.log(data);
});

Response:

{
  "data": {
    "getLocaleLanguage": {
      "id": "de",
      "label": "German",
      "status": 1,
      "mtime": "2022-05-28 06:26:33",
      "ctime": "2022-05-28 06:26:33",
      "editor": "setup"
    }
  }
}

Search languages#

The filter parameter is explained in the filter section of the GraphQL basics article.

query {
  searchLocaleLanguages(filter: "{\"==\": {\"locale.language.status\":1}}") {
    id
    label
    status
    mtime
    ctime
    editor
  }
}
let filter = {
    "==": {"locale.language.status":1}
};
const fstr = JSON.stringify(filter).replace(/"/g, '\\"');
const body = JSON.stringify({'query':
`query {
  searchLocaleLanguages(filter: "` + fstr + `") {
    id
    label
    status
    mtime
    ctime
    editor
  }
}`});

fetch($('.aimeos').data('graphql'), {
    method: 'POST',
    credentials: 'same-origin',
    headers: { // Laravel only
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    },
    body: body
}).then(response => {
    return response.json();
}).then(data => {
    console.log(data);
});

Response:

{
  "data": {
    "searchLocaleLanguages": [
      {
        "id": "de",
        "label": "German",
        "status": 1,
        "mtime": "2022-05-28 06:26:33",
        "ctime": "2022-05-28 06:26:33",
        "editor": "setup"
      },
      {
        "id": "en",
        "label": "English",
        "status": 1,
        "mtime": "2022-05-28 06:26:33",
        "ctime": "2022-05-28 06:26:33",
        "editor": "setup"
      }
    ]
  }
}

Save single language#

mutation {
  saveLocaleLanguage(input: {
    code: "xa"
    label: "Test language"
  }) {
    id
  }
}
const body = JSON.stringify({'query':
`mutation {
  saveLocaleLanguage(input: {
    code: "xa"
    label: "Test language"
  }) {
    id
  }
}`});

fetch($('.aimeos').data('graphql'), {
    method: 'POST',
    credentials: 'same-origin',
    headers: { // Laravel only
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    },
    body: body
}).then(response => {
    return response.json();
}).then(data => {
    console.log(data);
});

Response:

{
  "data": {
    "saveLocaleLanguage": {
      "id": "xa"
    }
  }
}

Save multiple languages#

mutation {
  saveLocaleLanguages(input: [{
    code: "xb"
    label: "Test language 2"
  },{
    code: "xc_US"
    label: "Test language 3"
  }]) {
    id
  }
}
const body = JSON.stringify({'query':
`mutation {
  saveLocaleLanguages(input: [{
    code: "xb"
    label: "Test language 2"
  },{
    code: "xc_US"
    label: "Test language 3"
  }]) {
    id
  }
}`});

fetch($('.aimeos').data('graphql'), {
    method: 'POST',
    credentials: 'same-origin',
    headers: { // Laravel only
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    },
    body: body
}).then(response => {
    return response.json();
}).then(data => {
    console.log(data);
});

Response:

{
  "data": {
    "saveLocaleLanguages": [
      {
        "id": "xb"
      },
      {
        "id": "xc_US"
      }
    ]
  }
}

Delete single language#

mutation {
  deleteLocaleLanguage(id: "xa")
}
const body = JSON.stringify({'query':
`mutation {
  deleteLocaleLanguage(id: "xa")
}`});

fetch($('.aimeos').data('graphql'), {
    method: 'POST',
    credentials: 'same-origin',
    headers: { // Laravel only
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    },
    body: body
}).then(response => {
    return response.json();
}).then(data => {
    console.log(data);
});

Response:

{
  "data": {
    "deleteLocaleLanguage": "xa"
  }
}

Delete multiple languages#

mutation {
  deleteLocaleLanguages(id: ["xb", "xc_US"])
}
const body = JSON.stringify({'query':
`mutation {
  deleteLocaleLanguages(id: ["xb", "xc_US"])
}`});

fetch($('.aimeos').data('graphql'), {
    method: 'POST',
    credentials: 'same-origin',
    headers: { // Laravel only
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    },
    body: body
}).then(response => {
    return response.json();
}).then(data => {
    console.log(data);
});

Response:

{
  "data": {
    "deleteLocaleLanguages": [
      "xb",
      "xc_US"
    ]
  }
}

Comments

Become an Aimeos Partner

Aimeos partners are first-class specialists in creating or hosting your Aimeos e-commerce project. They have proven their expertise by building top level e-commerce applications using Aimeos.