Rest Endpoint
This documentation is deprecated.
The documentation has moved
New Location https://project.pages.drupalcode.org/string/
Exposes Strings as custom rest resources that can be consumed by the popular i18next JavaScript Library. Two endpoints are provided by the module,
- String i18next Collection
- String i18next Item
String i18next Collection endpoint
Canonical Url for collection endpoint is /api/v1/string/i18next/{language_code}
Where, {language_code} is the identifier for the language code.
A special reserved string default can be used as "language_code" to let Drupal decide the language from context. This can be useful in partially decoupled scenario where the JavaScript application is served by Drupal.
Example
An example endpoint output at /api/v1/string/i18next/en?_format=json after enabling the endpoint via Rest UI. Notice how the placeholders also gets converted to i18next compatible placeholders in strings.
{
"string_demo": {
"dashboard": {
"welcome_message": {
"short": {
"string": "Hello {{name}}!"
},
"long": {
"string": "Hello {{name}}! Welcome back, good to see you again."
}
},
"greetings": {
"short_short_greeting": {
"string": "Sup {{name}}!"
}
}
},
"search": {
"result": {
"items_count": {
"string": "{{count}} item found"
}
}
},
"bar": {
"string": "Bar"
}
},
"group": {
"label": {
"string": "Groups"
}
},
"drupal": {
"module": {
"extend": {
"label": {
"string": "Extend"
}
}
},
"node": {
"content": {
"label": {
"string": "Pages"
}
},
"search_result_summary": {
"string": "One item found."
}
}
}
}String i18next Item endpoint
1. To get all strings under namespace "string_demo" in English (en).
/api/v1/string/i18next/en/string_demo?_format=json
{
"dashboard": {
"welcome_message": {
"short": {
"string": "Hello {{name}}!"
},
"long": {
"string": "Hello {{name}}! Welcome back, good to see you again."
}
},
"greetings": {
"short_short_greeting": {
"string": "Sup {{name}}!"
}
}
},
"search": {
"result": {
"items_count": {
"string": "{{count}} item found"
}
}
},
"bar": {
"string": "Bar"
}
}
2. To get all strings under namespace "string_demo.search" in English (en).
/api/v1/string/i18next/en/string_demo.search?_format=json
{
"result": {
"items_count": {
"string": "{{count}} item found"
}
}
}Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion
Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.