# core/browseruitext (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/core/browseruitext/

Browser UI text. (the same table and the same locale selection as the original core/browseruitext.js)
- Text for what the browser used to draw over the page (the title and buttons of JavaScript question dialogs, the items of the edit field context menu and the touch quick menu).
  In both engines, on the web and the desktop alike, the engine draws these, so it needs the same text. (core/modaldialog.rs, ui/uiinputfield.rs, ui/uiinputfieldmenu.rs)
- The text is a table made by looking up Chromium's translations (chrome/app/resources/generated_resources_*.xtb, ui/strings/translations/ui_strings_*.xtb,
  components/strings/components_strings_*.xtb) by grit message ID and converting them to their on-screen form. (browseruitext.json, 82 desktop locales)
  Chrome's Views menus draw with the accelerator markers "(&U)" and "&" removed (gfx RemoveAcceleratorChar), and Mac removes them with FixUpWindowsStyleLabel. The table holds the text with them removed.
- Chrome draws in its own UI language. Standing in for it, the locale is picked with Chrome's rules from the preferred languages in order (on the desktop the system preferred languages via sys-locale, on the web navigator.languages like the original).
  (l10n_util's GetApplicationLocale and language_tag_matcher: the same name if present, es-* is es-419, pt is pt-BR, zh is zh-CN, zh-Hant is zh-TW,
  en, en-PH and en-LR are en-US, en-CA and other en-* are en-GB, the old names iw, no, tl, in are he, nb, fil, id. en-US if nothing matches)
  zh-MO is treated as zh-HK following CLDR's parent locale zh-Hant-HK, and zh-SG as zh-CN. (not verified by running Chrome's ICU4X data)

Example: Read question dialog button text and the chosen locale (desktop)

```rust
use vanilla::core::browseruitext::{read_browser_ui_locale, read_browser_ui_text, BrowserUiText};

let ok_text = read_browser_ui_text(BrowserUiText::Ok);
let cancel_text = read_browser_ui_text(BrowserUiText::Cancel);
assert!(!ok_text.is_empty());
assert!(!cancel_text.is_empty());
assert!(!read_browser_ui_locale().is_empty());
```

## Functions and constants

- `pub fn read_browser_ui_text(text: BrowserUiText) -> String` (method, since 0.4.0): Browser UI text. (the chosen locale, en-US if missing in that locale)
  - The table is read on the first call per thread, and the locale is chosen then by the system preferred languages.
  - `text` BrowserUiText: Kind of text to read.
  - returns String: Text in that locale. (empty string if missing in en-US too)
- `pub fn read_browser_ui_locale() -> String` (method, since 0.4.0): Chosen locale.
  - returns String: Name of the locale chosen from the table. (such as ko, en-US, zh-TW, en-US if nothing matched)

## BrowserUiText (enum) (Clone, Copy, Debug, PartialEq, Eq)

Text kind. (the table key)

- `Undo`: Undo.
- `Redo`: Redo.
- `Cut`: Cut.
- `Copy`: Copy.
- `Paste`: Paste. (Windows, Linux)
- `PasteMac`: Paste. (Mac, the translation may differ)
- `PastePlainText`: Paste as plain text. (Windows, Linux)
- `PasteMatchStyle`: Paste and Match Style. (Mac)
- `SelectAll`: Select all. (Windows, Linux)
- `SelectAllMac`: Select All. (Mac)
- `Emoji`: Emoji. (Windows)
- `EmojiMac`: Emoji & Symbols. (Mac)
- `WritingDirection`: Writing Direction submenu.
- `WritingDirectionDefault`: Writing direction default.
- `WritingDirectionLeftToRight`: Left to Right.
- `WritingDirectionRightToLeft`: Right to Left.
- `Inspect`: Inspect.
- `PageSays`: Question dialog title. ("This page says" for pages without an origin)
- `Ok`: OK.
- `Cancel`: Cancel.
- `PeriodKey`: Name of the period key in shortcut text.
- `WindowsKey`: Name of the Windows key in shortcut text.
- `TouchCut`: Cut, copy and paste in the touch quick menu. (IDS_APP_CUT, IDS_APP_COPY, IDS_APP_PASTE in ui_strings)
- `TouchCopy`: Copy in the touch quick menu. (IDS_APP_COPY)
- `TouchPaste`: Paste in the touch quick menu. (IDS_APP_PASTE)
