是否可以使用ui-router来i18n /本地化我的应用程序?

时间:2021-08-31 11:02:26

First of all, ui-router is really a huge improvement on any AngularJS app that pretends to be flexible and well structured. Thank you for your effort!

首先,ui-router对于任何假装灵活且结构合理的AngularJS应用程序来说确实是一个巨大的进步。感谢你的付出!

In an application that I'm working on, we need to provide i18n of its paths.

在我正在开发的应用程序中,我们需要提供其路径的i18n。

Due to the nature of it, we need to deal with an endpoint that brings the available languages on the app.

由于它的性质,我们需要处理在应用程序上带来可用语言的端点。

So, the user enters on the app, and we have the following possibilities:

因此,用户输入应用程序,我们有以下可能性:

  1. Without a locale: http://www.app.com(/);
  2. 没有语言环境:http://www.app.com(/);

  3. With a valid locale: http://www.app.com/:i18n(/);
  4. 使用有效的区域设置:http://www.app.com/:i18n(/);

  5. With an invalid locale string: http://www.app.com/articles(/) - The :i18n path param is interpreted as articles;
  6. 使用无效的区域设置字符串:http://www.app.com/articles(/) - :i18n路径参数被解释为文章;

  7. With a valid locale but not available: http://www.app.com/ru(/) - The :i18n path param is an unavailable locale;
  8. 使用有效的区域设置但不可用:http://www.app.com/ru(/) - :i18n路径参数是不可用的区域设置;

I need to be able to:

我需要能够:

  1. Load the API endpoint that gives the available languages;
  2. 加载提供可用语言的API端点;

  3. Parse the URL provided, change if necessary, and if so, replace it;
  4. 解析提供的URL,必要时进行更改,如果需要,请将其替换;

  5. During the app runtime, the possibility to change the i18n param through something like a button and:
    1. Inherit the current params, replacing the i18n one;
    2. 继承当前的params,取代i18n;

    3. Trigger the elements that need to know about the i18n change (can be resolves, on an abstract route, or even the current;
    4. 触发需要了解i18n变化的元素(可以解析,在抽象路径上,甚至是当前;

    5. With the ii, the possibility to deal with this without reloading the entire app (be able to only change the data used on the view; I'll use a feedback to inform the load of the new data);
    6. 使用ii,可以在不重新加载整个应用程序的情况下处理此问题(只能更改视图上使用的数据;我将使用反馈来通知新数据的加载);

  6. 在应用程序运行时期间,可以通过类似按钮的方式更改i18n参数,并:继承当前参数,替换i18n;触发需要了解i18n更改的元素(可以解析,在抽象路由上,甚至是当前;使用ii,可以在不重新加载整个应用程序的情况下处理此问题(只能更改使用的数据)在视图上;我将使用反馈来通知新数据的加载);

One point is that, for example, if the user changes the locale to one that doesn't have content for the desired language, the app needs to redirect to a state that informs it to the user. I've thought, if its possible to trigger the elements on i18n change, and there's resolves on the state, on a rejection of one, it can dispatch a $stateChangeError, or something.

有一点是,例如,如果用户将语言环境更改为没有所需语言内容的语言环境,则应用程序需要重定向到通知用户的状态。我曾经想过,如果有可能触发i18n上的元素更改,并且已经解决了状态,拒绝一个,它可以调度$ stateChangeError,或者其他东西。

Ultimately, if I'm dealing with something that can be much simpler, please let me know... The use of a server configuration (the final server of this app will be an Apache), isn't that possible and, because the locales available comes from an API, I guess there's not much to deal with a .htaccess, isn't right?

最后,如果我正在处理更简单的事情,请告诉我...使用服务器配置(此应用程序的最终服务器将是Apache),这是不可能的,因为locales可用来自一个API,我想没有太多可以处理的.htaccess,不对吗?

Thanks!

1 个解决方案

#1


1  

I use https://github.com/vizo/angular-ui-router-i18n in my application, and works.

我在我的应用程序中使用https://github.com/vizo/angular-ui-router-i18n,并且正常工作。

that is my application porte.com.br/en

这是我的应用程序porte.com.br/en

I found a error, not work without locale

我发现了一个错误,没有语言环境就行不通

I send a pull request to vizo, but, at moment, I don't receive any feedback.

我向vizo发送拉取请求,但是,我暂时没有收到任何反馈。

But in my fork was working, try it

但在我的叉子工作,尝试它

#1


1  

I use https://github.com/vizo/angular-ui-router-i18n in my application, and works.

我在我的应用程序中使用https://github.com/vizo/angular-ui-router-i18n,并且正常工作。

that is my application porte.com.br/en

这是我的应用程序porte.com.br/en

I found a error, not work without locale

我发现了一个错误,没有语言环境就行不通

I send a pull request to vizo, but, at moment, I don't receive any feedback.

我向vizo发送拉取请求,但是,我暂时没有收到任何反馈。

But in my fork was working, try it

但在我的叉子工作,尝试它