RESTful URL:应该在哪里放置语言环境? example.com/en/page与example.com/page?locale=zh-CN [英] RESTful URL: where should I put locale? example.com/en/page vs example.com/page?locale=en

查看:80
本文介绍了RESTful URL:应该在哪里放置语言环境? example.com/en/page与example.com/page?locale=zh-CN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在决定如何组织URL并将语言环境放入其中.我有两种选择:

I'm deciding how to organize URL and put locale into it. I have two choices:

  1. example.com/en/page
  2. example.com/page?locale=zh- Google方式
  3. en.example.com/page -不好,因为我正在使用子域
  1. example.com/en/page
  2. example.com/page?locale=en -- Google way
  3. en.example.com/page -- isn't good because I'm using subdomains

从一侧看,example.com/en/pageexample.com/page?locale=en看起来更好,更紧凑. 另一方面,对于具有两种表示形式的一种资源,我们有两个URL example.com/en/pageexample.com/ru/page. 当然,在example.com/page?locale=en的情况下,我们也为一个资源提供了两个URL,但就我的口味而言,它还是比较RESTful的.

From one side example.com/en/page looks better and more compact than example.com/page?locale=en. From other side we have two URLs example.com/en/page and example.com/ru/page for one resource with two representations. Of course in case example.com/page?locale=en we have two URLs for one resource too, but it is slightly more RESTful on my taste.

最佳做法是什么?您在使用什么,为什么?

What's the best practice? What are you using and why?

推荐答案

本地化是Restful API中内容协商的一部分.

Localization is part of Content-Negotiation in Restful API.

因此,我的首选方式是通过标头进行操作. HTTP提供了定义所需语言的标准方法.看看 Accept-Language 标头.

So my preferred way I would do it through headers. HTTP offers standard way of defining wanted language. Have a look at Accept-Language header.

这篇关于RESTful URL:应该在哪里放置语言环境? example.com/en/page与example.com/page?locale=zh-CN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆