GraphQL i18n
Internationalization and localization solution in GraphQL.
Features
- Flexible: Multiple storage adapters can be chosen to store i18n.
- Easily use: Add a simple middleware, and your service is ready for i18n.
Installation
yarn add graphql-i18n
Example
Setup GraphQL Server
;; ; ; ; ; ;;;i18n.syncwhere, dataEn, 'en';i18n.syncwhere, dataZh, 'zh'; ; ; server.startconsole.log'Server is running on http://localhost:4000'
Now, you can get i18n by add directive locale
in your Query.
query { book @locale(lang: "en") { name author { name } } books @locale(lang: "zh") { name author { name } }}
API
Types
i18n.sync(where, data, language)
Create or update i18n data.
i18n.find(where, language)
Find list of i18n data. If language
is not existent, graphql-i18n will find default language.
i18n.findOne(where, language)
Find one of i18n data. If language
is not existent, graphql-i18n will find default language.
i18n.destroy(where, language)
Destroy one of i18n data.
Adapters
Memory Adapter
Store i18n data in memory. Data will be lost after closing server.
;;
MongoDB Adapter
Store i18n data in MongoDB.
;;
Firebase Adapter (coming soon)
Store i18n data in Firebase.
License
Apache-2.0