douhanxujiuji6098 2018-04-12 17:58
浏览 50

使用MySQL的PHP​​应用程序中的语言支持

I want to provide language support in several different languages in a php web application. There are obviously several different ways to do this. In the past I used to store a variable in a php file for every language such as en.php for english support and fr.php for french support. For example, for the words Good Morning I would store it in a key $goodmorning then define it in both files and point to one or the other file with an if statement depending on user input.

It worked great but it was a lot of work. Is there a more efficient way to do this? I thought about storing the words in a database table called language_support. The table would look as follow

id | en    | fr   | es   |last_update
1  | hello | allo | hola | 04/12/2018

But my question is, how would I teach my program to recognize the words?

  • 写回答

1条回答 默认 最新

  • drgm51600 2018-04-12 18:07
    关注

    Look into PHP's _() and __() functions. This is for multi-language support of internal strings, not content. In other words, it's for the "Press any key to continue" or "Enter customer name" prompts, not for the blog articles. The general way it works is that you have a text file for each language, each text file with all the internal strings in the source and target languages.

    You would use, for example, _("Good Morning!"), and assuming you had set the language to German, the output would be "Guten Tag!"

    I'm at work, so I can't show you any PHP code right now, but that should be enough to Google. :)

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line