我正在尝试设置相同的全局laalevel语言环境:
config('app.locale')
Run Code Online (Sandbox Code Playgroud)
与碳合作.
看起来你可以通过使用以下两种方法来实现:
Carbon::setLocale('fr')
Run Code Online (Sandbox Code Playgroud)
要么
setlocale(LC_TIME, 'theLocale');
Run Code Online (Sandbox Code Playgroud)
所以我尝试过使用中间件或提供商,但没有成功.
(为什么这不是laravel的默认功能?)
我正在尝试创建一个简单的 switch 函数,它采用第一个参数,该参数必须是字符串和一个对象的联合,该对象具有基于第一个参数联合的键并且可以返回任何值。
export const mySwitch = <T extends string>(value: T, possibilities: {[key in T]: any}): any => {
return possibilities[value];
};
Run Code Online (Sandbox Code Playgroud)
典型用法是
let option: "val1" | "val2" | "val3" = "val1";
// should returns s1
// Impossible should be type-checked as an error since it's not part of the option union type
mySwitch(option, {val1: "s1", val2: "s2", val3: "s3", impossible: "impossible"});
Run Code Online (Sandbox Code Playgroud)
我的问题发生是因为泛型类型T必须是 astring才能用作对象键。我不知道你怎么能说T是string.
我试过T extends string没有成功。