在Angular或Laravel中转换API响应数据(发送到Frontend之前)

发布于 2025-02-06 00:48:31 字数 228 浏览 4 评论 0原文

我的前端是角,在拉拉维尔(Laravel)的后端。有一个API,我会在数组中获得颜色的名称。我需要根据默认语言集进行翻译。我有两个JSON文件en.json,de.json在前端和后端。

有什么办法可以通过Angular或Laravel翻译API响应数据,我可以将翻译数据发送到Frontend吗?我们可以像静态数据一样使用此翻译中的JSON文件吗?

我搜索但不幸找到了任何解决方案。

请帮助和指导。

I have frontend in angular and backend in Laravel. There is one API by which I gets names of colors in array. I need to translate that depending on default language set. I have two json files en.json, de.json in frontend and backend.

Is there any way by which I can translate API response data in angular or in Laravel can I send translated data to frontend? Can we make use of json files in this translation like we use for static data?

I searched but unfortunate to find any solution to this.

Please help and guide.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

江湖彼岸 2025-02-13 00:48:32

如何以及在何处翻译的方式取决于您的应用程序特定的。

通常,静态数据(有限且不经常变化)在您的JS应用程序的侧面翻译,并且可以经常扩展或更新的动态数据,通常在后端侧翻译并已通过API进行了翻译。

例如,如果可能的颜色总数有限,并且您直接从前端查询第三方API,则在Angular应用中使用翻译是有意义的。

如果第三方API在Laravel侧查询,然后将结果传递给您的前端应用程序,则可以添加新颜色等。-将已经翻译的数据发送到Angular是有意义的。

The way how and where to translate depends on your app specific.

Usually, the static data (which is limited and not changing often) is translated on the side of your js app, and the dynamic data, which can be extended or updating often, usually translated on backend side and returned already translated via API.

For example, if the total amount of possible colors is limited and you query 3rd party API directly from the frontend - it makes sense to use translations in your Angular app.

If 3rd party API is queried on Laravel side and then the results passed to your frontend app, new colors can be added often etc. - it makes sense to send already translated data to Angular.

木格 2025-02-13 00:48:32

您可以在翻译方面使用此库 https://github.com/ngithub.com/ngx-translate/核心

从那里而不是返回准备显示后端的值,您可以返回JSON键,与该库中提供的管道一起使用

There is this library you can use in frontend for your translation https://github.com/ngx-translate/core

From there instead of returning ready to show values from your backend you can returns JSON keys to be used alongside the provided pipe in that library

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文