I've got a JS code where it says
!{JSON.stringify(t("some.thing"))};
It is used for translation/internationalization with i18next. But I don't understand the !{...}
part.
I know what the JSON.stringify
does. I know what the negation operator !
means. I don't understand it in combination with the t()-function: When I use it without the !{...}
part, it says
Uncaught ReferenceError: t is not defined
But with the !{...}
part, it translates the part some.thing
correctly.
some.thing
is a key in different JSON files for different languages, e.g. a JSON file for english:
{
"some": {"thing": "something"}
}
and a JSON file for German:
{
"some": {"thing": "irgendetwas"}
}
Depending on what language is set on your computer, the function t("some.thing")
will return the corresponding value. If the language of your computer is set to english it will return "something". If it is in German it will return "irgendetwas".
答案 0 :(得分:2)
大括号与对象无关,感叹号与否定无关。它是JavaScript中使用的变量的jade语法:
答案 1 :(得分:-1)
JSON.stringify is a Javascript built in function to convert a JSON
object into a string. The reverse operation would be JSON.parse().
In your code, it seems that t('some.thing')
is a minified function that returns an Object, that is converted into a string
and then, checked with a negation operator !
.
答案 2 :(得分:-1)
The !
is not equal to
.
So technically this would translate to:
If the output of
JSON.stringify(t("some.thing"))
isempty
ornull
. Returntrue