Rest Endpoint

Last updated on
15 May 2025

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,

  1. String i18next Collection
  2. 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

Page status: Deprecated

You can: