duanmei1930 2013-10-30 14:55
浏览 68
已采纳

Symfony2和Angular.JS之间共享的翻译

I am looking for a good way to share my translations between my Symfony2 App and my Angular.JS App, they are essentially the same app, however they act very differently.

First of all I have made a directive to allow for templating using [[ variable ]] in my angular js app, so I can use the variables from twig alongside my variables in angular.

So what I want to achieve is to translate my sentences into the localisation that the user prefers.

So my conclusion is that I want to use the translations features of Symfony, as there is no good support for that in Angular. I also want to use all the built in features that Symfony includes, which is like update the files automatically, support YAML etc. But I need to work out how to transfer them to my JS application and how I can detect them in Symfony, so both applications can use them.

So my initial idea:

Change the capturing of translations or at least add an additional one to the scope.

{% trans %}Hello [[name]]{% endtrans %}

<trans name="My Name" translation="Hello [[name]]" />

And also support all other functionalities with pluralisation etc.

This would then generate a file that has the translations, and pluralisation etc.

Request language through angular ajax call and save this into a local storage on the client side.

This would allow me to replace the directive above of trans with the proper value. This is not a problem to set up. However it needs to be exported from whatever format to JSON that angular can read.

Then there needs to be a matcher, and there needs to be support for pluralisation and all other features available.

Other Ideas

It might be better in general to not use the Symfony2 translations when you do an Angular.JS App, and thereby only use the angular translations, otherwise the text written in Symfony2 Twigs and is translated would probably not be translatable in Angular. But the generation of these files I find it to be better if Symfony could capture and spit out.

I think this needs to be a bit of work to be solid, but I feel that this needs to be solved. Any ideas and helpful comments are appreciated, I am considering to start a project for this on GitHub, to give proper support for this. But if there's such already it might just be better to work with that.

/Marcus

  • 写回答

4条回答 默认 最新

  • dstew32424 2013-11-09 18:33
    关注

    I Ended up using this solution. Solves all my problems:

    http://cliffmeyers.com/blog/2013/3/11/integration-angularjs

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出