"b","в" => "v","г" => "g","д" => "d","е" => -6ren">
gpt4 book ai didi

javascript - Strtr 用于 angularjs,就像 PHP 中一样(尝试音译)

转载 作者:行者123 更新时间:2023-12-02 14:15:11 27 4
gpt4 key购买 nike

这是我的 PHP 代码,它完成了我需要它完成的工作,但它需要重新加载页面才能真正工作。

<?php
$seo_link = array("а" => "a","б" => "b","в" => "v","г" => "g","д" => "d","е" => "e","ж" => "zh","з" => "z","и" => "i","й" => "y","к" => "k","л" => "l","м" => "m","н" => "n","о" => "o","п" => "p","р" => "r","с" => "s","т" => "t","у" => "u","ф" => "f","х" => "h","ц" => "c","ч" => "ch","ш" => "sh","щ" => "sht","ь" => "y","ю" => "yu","я" => "ya"," " => "-","А" => "a","Б" => "b","В" => "v","Г" => "g","Д" => "d","Е" => "e","Ж" => "zh","З" => "z","И" => "i","Й" => "y","К" => "k","Л" => "l","М" => "m","Н" => "n","О" => "o","П" => "p","Р" => "r","С" => "s","Т" => "t","У" => "u","Ф" => "f","Х" => "h","Ц" => "c","Ч" => "ch","Ш" => "sh","Щ" => "sht","Ю" => "yu","Я" => "ya","." => "");

$product_name = "Това е малко куче";

echo $product_name . "<br>";

echo strtr($product_name, $seo_link);

//output tova-e-malko-kuche

?>

有什么方法可以在 AngularJS 中重新创建该代码吗?我需要它基本上实时发生。

示例:http://howtobg.com/catalog/pages/seo_products.php

当你输入一些文本时会被打印出来,我的想法是当我写的时候

“Куче” angularJS 将其打印出来,但每个字母都被翻译为“Kuche”

有人可以指出我应该在哪里寻找什么吗,因为到目前为止我自己找不到任何东西

提前致谢。

最佳答案

如果只是为了转换字母,您可以将此部分与对象一起用作字母的哈希表。

function convert(s) {
var letters = { "а": "a", "б": "b", "в": "v", "г": "g", "д": "d", "е": "e", "ж": "zh", "з": "z", "и": "i", "й": "y", "к": "k", "л": "l", "м": "m", "н": "n", "о": "o", "п": "p", "р": "r", "с": "s", "т": "t", "у": "u", "ф": "f", "х": "h", "ц": "c", "ч": "ch", "ш": "sh", "щ": "sht", "ь": "y", "ю": "yu", "я": "ya", " ": "-", "А": "a", "Б": "b", "В": "v", "Г": "g", "Д": "d", "Е": "e", "Ж": "zh", "З": "z", "И": "i", "Й": "y", "К": "k", "Л": "l", "М": "m", "Н": "n", "О": "o", "П": "p", "Р": "r", "С": "s", "Т": "t", "У": "u", "Ф": "f", "Х": "h", "Ц": "c", "Ч": "ch", "Ш": "sh", "Щ": "sht", "Ю": "yu", "Я": "ya", ".": "" };
return s.split('').map(function (c) {
return c in letters ? letters[c] : c;
}).join('');
}

console.log(convert("Това е малко куче"));

关于javascript - Strtr 用于 angularjs,就像 PHP 中一样(尝试音译),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39099413/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com