您好,我正在构建一个演示应用程序只是为了学习 React,但我对翻译过程有点困惑。我想要做的是拥有一个多语言网站,默认语言为“希腊语”,辅助语言为“英语”。当启用希腊语时,URL 不应在 URL 中包含任何区域设置,但当启用英语时,应使用 /en/ 重写 URL。
i18n 配置
import translationEn from './locales/en/translation';
import translationEl from './locales/el/translation';
import Constants from './Utility/Constants';
i18n
.use(Backend)
.use(LanguageDetector)
.use(initReactI18next)
.init({
fallbackLng: 'el',
debug: true,
ns: ['translations'],
defaultNS: 'translations',
detection: {
order: ['path'],
lookupFromPathIndex: 0,
},
resources: {
el: {
translations: translationEl
},
en: {
translations: translationEn
}
},
interpolation: {
escapeValue: false, // not needed for react as it escapes by default
}
}, () => {
// Why the fuck this doesnt …Run Code Online (Sandbox Code Playgroud) 我想在最后一个"/"之后解析字符串.例如:
http://127.0.0.1/~dtm/index.php/en/parts/engine
Run Code Online (Sandbox Code Playgroud)
解析"引擎".
我尝试用Regexp做,但是作为regexp的新手我坚持在解决方案附近.此模式似乎很容易破解(/ engine /会破坏它).需要以某种方式使它更稳定.
$pattern = ' \/(.+^[^\/]?) ' ;
Run Code Online (Sandbox Code Playgroud)
import math
from math import sqrt
Hailey=[0,4,1,4,0,0,4,1]
Verica=[3,0,0,5,4,2.5,3,0]
temp=[]
distance=0
x=0
for i in range(0,len(Hailey)):
if (Hailey[i]!=0 and Verica[i]!=0):
temp[x]=math.sqrt(abs(Hailey[i]**2) - abs(Verica[i]**2))
x=x+1
for i in range(0,len(temp)):
distance=distance+temp[i]
print("distance is",distance)
Run Code Online (Sandbox Code Playgroud)
我试图制作一个程序,找到两个人之间的欧几里德距离.它似乎没有数学上的正确性,我得到这个:
distance=distance + math.sqrt(abs(Hailey[i]**2) - abs(Verica[i]**2))
ValueError: math domain error
Run Code Online (Sandbox Code Playgroud)