Localization for REST APIs

后端 未结 2 811
孤独总比滥情好
孤独总比滥情好 2021-02-20 11:07

I am starting this discussion to gather more info on localization practices for APIs. It seems HTTP does NOT provide sufficient guidance and even the state of practice is not su

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-20 11:44

    I would keep all data in a universal locale independent format. For numbers using . as a decimal separator, date and time using ISO 8601 and in UTC, etc.

    Provide localized text only if it absolutely necessary. In that case get the locale from accept-language header field, and if you have the localized string pass that. If not fallback to the string you have.

    For example, you might a multilingual product database that contains product data in several languages. When you write an API for the database you can select the product data in user's language (if any).

    Here is a sample.

提交回复
热议问题