dongyu4455 2018-08-29 15:19
浏览 90
已采纳

PHP-SQL - 国际化和本地化 - Gettext-POedit

I'm creating a site that I want to display in multiple languages for different countries, but this is my first time doing this and not sure what est practices are.

So for all my static text in my code I just wrap it in the translate function and POedit is able to extract the strings.

Then for all my dynamic text that is being generated via PHP from my DB, when I add something new to my DB on the back end, I also do a file_put_contents() into the PO file as well so I have those strings to be translated.

So everything in my database is in english but gets added to my PO file. The issue is I also have a search bar. This searches my DB for various items but can only search in english.

What I am trying to do at the moment is something like this, where I translate the actual input using Google Translate API and search in English:

$term = $_POST['search_text'];
$result = $translate->translate($term, [
    'target' => 'en'
]);
$translation = $result['text'];
$new_term = '%'.$translation.'%';
$params = [$new_term];
$sql = "SELECT * FROM products WHERE product_name LIKE ?";
$stmt = DB::run($sql,$params);

Obviously this isn't perfect because I'm relying on Google to do translate the search terms, but it is picking up the right results in general.

Is there a better way of doing this because this seems like I'm going about it the wrong way. Any help or suggestions with this would be greatly appreciated.

  • 写回答

1条回答 默认 最新

  • dongyi9484 2019-07-31 09:08
    关注

    What I ended up doing was searching in english and seaching with a translation and combining the results so it will hopefully pick up everything.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格