AI Translator
<msc-ai-translator />
is a web component based on Chrome Built-in AI > Language Detector API and Translator API.
Web developers could use <msc-ai-translator />
wrap article which want to adopt translate language feature.
Check the following demo and just press the 「Translate」 button. Then Gemini will give you a translation which the language you just picked.
Let's see what can <msc-ai-translator />
do ?
官方表示,為了使全世界的玩家可以持續且深入地遊玩優質的遊戲內容,《艾爾登法環》作為一款全新的動作 RPG 作品,於製作過程中完美結合了 FromSoftware 的過人開發能力,以及萬代南夢宮娛樂於海外市場的出色行銷能力。
除了 FromSoftware 最擅長的刺激動作場景,遊戲內的世界觀更是由 FromSoftware 的宮崎英高,以及以奇幻小說《冰與火之歌》系列聞名全球的喬治‧R.R‧馬丁共同製作。刺激的動作場景、壯闊的世界觀、內容豐富的廣大世界,以及高自由度的探索過程,讓玩家得以享受前所未有的遊戲體驗,本作因此獲得壓倒性的好評。除了提供 14 種語言版本 ※,於發售前舉辦的網路測試內容讓玩家更為期待,成功為《艾爾登法環》帶來突破 1200 萬套的銷售佳績。
官方表示,《艾爾登法環》今後不只是遊戲,也將作為遊戲 IP 持續發展,敬請持續關注以獲得更多消息。
Basic Usage
<msc-ai-translator />
is a web component. All we need to do is put the required script into your HTML document. Then follow <msc-ai-translator />
's html structure and everything will be all set.
Required Script
Structure
Put <msc-ai-translator />
into HTML document. It will have different functions and looks with attribute mutation.
Otherwise, developers could also choose remoteconfig to fetch config for <msc-ai-translator />
.
JavaScript Instantiation
<msc-ai-translator />
could also use JavaScript to create DOM element. Here comes some examples.
Style Customization
Developers could apply styles to decorate <msc-ai-translator />
's looking.
Delevelopers could add className - align-container-size
to make <msc-ai-translator />
's size same as container's size.(default is inline-size: 100%
only)
Otherwise, apply pseudo class ::part(trigger) to direct style the translate button.
Attributes
<msc-ai-translator />
supports some attributes to let it become more convenience & useful.
disabled
Hides the translate trigger button once set. It is false by default (not set).
l10n
Set localization for title or action buttons.
- subject
:Set dialog subject.
- introduction
:Set dialog result title.
- selectlanguage
:Set language select title.
- translate
:Set translate trigger button's content. Web developer could add keyword {{language}} in sentence, <msc-ai-translator />
will replace it with the language you picked.
optionslanguage
Set language select's option display language. Default is "en".
Properties
Property Name | Type | Description |
---|---|---|
disabled
|
Boolean | Getter / Setter disabled. Hides the translate trigger button once set. It is false by default. |
l10n
|
Object | Getter / Setter localization for title or action buttons. Developers could set subject 、introduction 、selectlanguage and translate here. |
available
|
String | Getter available. Web developers will get "no" if current browser doesn't support Build-in AI. |
translation
|
String | Getter the last translation. |
optionslanguage
|
String | Getter / Setter language select's option display language. |
Mathod
Mathod Signature | Description |
---|---|
translate({ content = '', useDialog = false, targetLanguage })
|
Go translating. This is an async function. Default will take <msc-ai-translator />'s children's text content to translate. Developers could set useDialog to decide display translation by dialog or not. |
Events
Event Signature | Description |
---|---|
msc-ai-translator-error
|
Fired when translate process error occured. Developers could gather message information through event.detail. |
msc-ai-translator-process
|
Fired when prompt processing. |
msc-ai-translator-process-end
|
Fired when prompt process end. |