如何从谷歌应用程序脚本中的谷歌翻译语言代码中获取语言名称?
I have a script I'm using with the google translate api. I am translating like this:
LanguageApp.translate(content, 'en', 'es')
I now need to translate content
to many more languages, and as languages are added or dropped I don't want to update much, so how can I get the name of a language from its language 'code'?
I'm expecting something like this
LanguageApp.getNameFromCode('es')
and it would return "spanish" in this case.
How can I achieve this?
If it's not possible, I can use JS to on my frontend, or PHP in my backend, but using GAS is the most preferable way for me.
我有一个我正在使用谷歌翻译api的脚本。 我正在这样翻译: p>
LanguageApp.translate(content,'en','es')
code> pre>
我现在需要将 content code>翻译成更多语言,并且随着语言的添加或删除,我不想更新,所以如何从其语言代码中获取语言的名称 '? p>
我期待这样的事情 p>
LanguageApp.getNameFromCode('es')
code> pre>
在这种情况下会返回“西班牙语”。 p>
如何实现这一目标? p>
如果是 不可能,我可以在我的前端使用JS,或者在我的后端使用PHP,但使用GAS对我来说是最好的方式。 p>
div>
This should be the method you are looking for:
List<Language> languages = translate.listSupportedLanguages(target);
I shared the Java code, but you can have a look at the documentation and choose the one that fits your application better.