Title: Theory / Important / Chrome / Grit

Fla: unit
Effect: run unit tests
Page: https://www.chromium.org/developers/tools-we-use-in-chromium/grit/grit-users-guide/
Prefix: ./tools/grit/grit.py
Context: grit

Fla: newgrd
Effect: create a skeleton of grit file
Page: https://www.chromium.org/developers/tools-we-use-in-chromium/grit/grit-users-guide/
Prefix: ./tools/grit/grit.py
Context: grit

Variable: name
Meaning: The textual ID of the message.
Page: https://www.chromium.org/developers/tools-we-use-in-chromium/grit/grit-users-guide/
Context: grit grd
Language: xml

Variable: desc
Meaning: A description of the message giving enough context to the translator to translate the message correctly
Page: https://www.chromium.org/developers/tools-we-use-in-chromium/grit/grit-users-guide/
Context: grit grd
Language: xml
Extra: (e.g. the message "Shut" might be a description of an action you need to take or the description of the status of something, so a description like e.g. "Shut the current dialog; button label" would help translators do the right thing).

Variable: Meaning
Meaning: This can provide a bit of context to the translators along with the 'desc' attribute.
Page: https://www.chromium.org/developers/tools-we-use-in-chromium/grit/grit-users-guide/
Context: grit grd
Language: xml
Extra: You can use this field to ensure that two messages that have the same text will not necessarily share the same translation.

Variable: internal_comment
Meaning: A message to developers
Page: https://www.chromium.org/developers/tools-we-use-in-chromium/grit/grit-users-guide/
Context: grit grd
Language: xml

Instruction: <ph>foo</ph>
Page: https://www.chromium.org/developers/tools-we-use-in-chromium/grit/grit-users-guide/
Effect: Insert a non-translatable string foo
Language: xml
Context: grit grd message

Instruction: <message name="name">
  foo
</message>
Page: https://www.chromium.org/developers/tools-we-use-in-chromium/grit/grit-users-guide/
Effect: Introduce a translatable string name with English content foo
Language: xml
Context: grit grd

Instruction: <ex>foo</ex>
Page: https://www.chromium.org/developers/tools-we-use-in-chromium/grit/grit-users-guide/
Effect: Add that the current ph content could be, for example, have value foo
Language: xml
Context: grit grd ph

Variable: name
Meaning: indicate that the value of ph is related to a variable with this name
Page: https://www.chromium.org/developers/tools-we-use-in-chromium/grit/grit-users-guide/
Context: grit grd ph
Language: xml

Question: how to deal with strings with leading/trailing whitespaces
Answer: Put the string in triple-single quote '''
Page: https://www.chromium.org/developers/tools-we-use-in-chromium/grit/grit-users-guide/
Context: grit grd

Instruction: <structure>
Page: https://www.chromium.org/developers/tools-we-use-in-chromium/grit/grit-users-guide/
Effect: todo if understood
Language: xml
Context: grit grd

Fla: build
Effect: make GRIT build RC files and resource header files from a .grd file.
Page: https://www.chromium.org/developers/tools-we-use-in-chromium/grit/grit-users-guide/
Prefix: ./tools/grit/grit.py
Context: grit grd

Instruction: <if expr="pred">
  foo
</if>
Page: https://www.chromium.org/developers/tools-we-use-in-chromium/grit/grit-users-guide/
Effect: If the python pred holds, then add foo to the current file, else ignore it
Language: xml
Context: grit grd

Variable: lang
Meaning: current language code in IETF format
Page: https://www.chromium.org/developers/tools-we-use-in-chromium/grit/grit-users-guide/
Context: grit grd if expr
Language: python

Variable: defs
Meaning: a map of C preprocessor defines to their values
Page: https://www.chromium.org/developers/tools-we-use-in-chromium/grit/grit-users-guide/
Context: grit grd if expr
Language: python

Instruction: pp_ifdef(name)
Page: https://www.chromium.org/developers/tools-we-use-in-chromium/grit/grit-users-guide/
Effect: same as #ifdef name
in C preprocessor
Language: python
Context: grit grd if expr

Instruction: pp_if(name)
Page: https://www.chromium.org/developers/tools-we-use-in-chromium/grit/grit-users-guide/
Effect: same as
#if name
in C preprocessor
Language: python
Context: grit grd if expr

Variable: allow_pseudo
Meaning: Whether to allow to build with pseudo-translated strings
Page: https://www.chromium.org/developers/tools-we-use-in-chromium/grit/grit-users-guide/
Context: grit grd <release>
Language: xml

Question: What to do if a string is needed only on some platform
Answer: uses <if> to ensure it's excluded from platform not using it
Page: https://www.chromium.org/developers/design-documents/ui-localization/
Context: chrome grd

Question: How to add a string
Answer: Check whether the string you need already exists. If you find a matching string, read the description to see how it's intended to be used, and leverage it if you can. Otherwise, continue.
Page: https://www.chromium.org/developers/design-documents/ui-localization/
Context: chrome grd
Answer2: Add the string to the grd file (generated_resources.grd, webkit_strings.grd, chromium_strings.grd or google_chrome_strings.grd).
Answer3: See tips on writing better user-facing strings.
Answer4: Include screenshots, meanings, and descriptions for all strings. This is crucial for high-quality translations.
Answer5: Use ICU message syntax to accommodate plurals and gender.
Answer6: As needed, surround the string with an appropriate <if> clause to ensure that it's only included it on platforms where it's actually used (e.g., Mac and Linux); this avoids needlessly increasing the download size. Strings used on all platforms can omit the <if> clause.

Question: How to include a string in code
Answer: include ui/base/l10n/l10n_util.h and chrome/grit/generated_resources.h.
Page: https://www.chromium.org/developers/design-documents/ui-localization/
Context: chrome grd
Answer2: To get the string, use l10n_util::GetStringUTF16. Alternately, you can use l10n_util::GetStringFUTF16 which will replace placeholders $1 through $4 with the extra arguments of GetStringFUTF16. Note that we generally prefer to use UTF-16 encoded strings for user-visible text.
Answer3: 1. Deal with message placeholder content. Example:
Hey <ph name="USER">%1$s<ex></ex></ph>, you have <ph name="NUMBER"><ex>10</ex>$2</ph> messages.

Question: How to add a new grdp file
Answer: add it to its parent grd file
Page: https://www.chromium.org/developers/design-documents/ui-localization/
Context: chrome grd

Question: How to add a new grd file
Answer: added to /src/tools/gritsettings/resource_ids
Page: https://www.chromium.org/developers/design-documents/ui-localization/
Context: chrome grd
Answer2: have a rule added to /src/chrome/chrome_resources.gyp.
Answer3: added to /src/tools/gritsettings/translation_expectations.pyl (or <message>s won't be translated).
Answer4: - If your new grd(p) will result in new XTB files after translation, you must commit placeholder .xtb files or else Chrome won't compile. The placeholders need to have a basic xml structure. Example for creating the XTBs:
> for lang in fr de en-GB etc; do echo '<?xml version="1.0" ?><!DOCTYPE translationbundle><translationbundle lang="'$lang'"></translationbundle>' > foo_strings_$lang.xtb; done
Answer5: - If your new grd will NOT be translated (set in translation_expectations.pyl and no XTB placeholder files required above), there is very minimal XML content required in your grd. Example:
<?xml version="1.0" encoding="utf-8"?>
<!--
This file contains all "about" strings.  It is set to NOT be translated, in translation_expectations.pyl.  en-US only.
-->
<grit base_dir="." latest_public_release="0" current_release="1"
    source_lang_id="en" enc_check="möl">
<outputs>
    <output filename="grit/about_strings.h" type="rc_header">
    <emit emit_type='prepend'></emit>
    </output>
</outputs>
<release seq="1" allow_pseudo="false">
    <messages fallback_to_english="true">
    <message name="IDS_NACL_DEBUG_MASK_CHOICE_DEBUG_ALL">
        Debug everything.
    </message>
    </messages>
</release>
</grit>

Question: What to put in a string description
Answer: Location: Button, title, link, drop-down menu, etc.
Page: https://www.chromium.org/developers/design-documents/ui-localization/
Context: chrome grd
Answer2: Grammar: Is this a noun or a verb? If it's an adjective, what is it describing?
Answer3: Audience: Who is the intended audience?
Answer4: Causality: What causes this message to appear? What is the next message that will appear?
Answer5: Placeholder: What do the placeholders mean? What are a few values that your placeholder may display? If you have multiple placeholders, do they need to be arranged in a certain way? Will this message replace a placeholder in another message?
Answer6: Length: Does this message have to have fewer than some number of characters? (For example, mobile products have limited UI space.) How should line breaks be dealt with? Are there character limits per line?

Question: How to add translation screenshot
Answer: Take a screenshot of the UI that displays the modified string (e.g. IDS_NEW_STRING in path/to/file.grd)
Save it under the screenshot directory for the file you are editing: path/to/file_grd/IDS_NEW_STRING.png. If path/to/file_grd doesn’t exist, create it. Only .png files are supported.
Page: https://www.chromium.org/developers/design-documents/ui-localization/
Context: chrome grd
Answer2: Run python tools/translation/upload_screenshots.py (without flags) to upload the screenshot to Google Cloud Storage.
Answer3: This will generate path/to/file_grd/IDS_NEW_STRING.png.sha1. Add this file to your CL and you are done. Don’t add the actual image to your CL.

Name: Translation screenshots
Definition: .png files provided by Chrome Developers to give translators more context about UI changes
Page: https://source.chromium.org/chromium/chromium/src/+/main:tools/translation/
Context: Chrome

Variable: path/foo_grd
Meaning: Repository containing hash of screenshot of UI containing strings of path/foo.grd
Page: https://source.chromium.org/chromium/chromium/src/+/main:tools/translation/
Context: Chrome

Variable: path/foo_grd/IDS_MESSAGE.png.sha
Meaning: The hash of a screenshot containing IDS_MESSAGE of path/foo.grd
Page: https://source.chromium.org/chromium/chromium/src/+/main:tools/translation/
Context: Chrome

Instruction: tools/translation/upload_screenshots.py
Page: https://source.chromium.org/chromium/chromium/src/+/main:tools/translation/
Effect: find png translation screenshot, upload them for translator, and add their hash
Context: Chrome

Instruction: tools/translation/helper/sanity_check.py
Page: https://source.chromium.org/chromium/chromium/src/+/main:tools/translation/
Effect: Attend to load all grd and grdp files
Context: Chrome