Add lit components localization

Localization is performed via the @lit/localize package, which has been
integrated into the repo. A I18nLitElement class which extends
LitElement has been included, which automatically sets up the
localization.

This CL also introduces localization to the flattenThreads feature.

Fixed: twpowertools:157
Change-Id: If01540b9c8d70876a648aa002a1e0a5bede8f383
diff --git a/src/common/litI18nUtils.js b/src/common/litI18nUtils.js
new file mode 100644
index 0000000..1f95baa
--- /dev/null
+++ b/src/common/litI18nUtils.js
@@ -0,0 +1,43 @@
+import {configureLocalization, updateWhenLocaleChanges} from '@lit/localize';
+import {LitElement} from 'lit';
+
+import MWI18nClient from '../common/mainWorldI18n/Client.js';
+import {allLocales, sourceLocale, targetLocales} from '../lit-locales/generated/locales.js';
+
+export class I18nLitElement extends LitElement {
+  #MWI18nClient;
+
+  constructor() {
+    super();
+    updateWhenLocaleChanges(this);
+    this.#MWI18nClient = new MWI18nClient();
+    this.#setUpLitL10n();
+  }
+
+  #setUpLitL10n() {
+    let pLocale;
+    if (chrome.i18n) {
+      pLocale = Promise.resolve(chrome.i18n.getUILanguage());
+    } else {
+      pLocale = this.#MWI18nClient.getUILanguage();
+    }
+    pLocale.then(browserLocale => {
+      let locale = browserLocale.substr(0, 2).toLowerCase();
+      if (locale == 'pt') locale = 'pt_BR';
+      const sanitizedLocale = allLocales.includes(locale) ? locale : 'en';
+      setLocale(sanitizedLocale);
+    });
+  }
+}
+
+export const {getLocale, setLocale} = configureLocalization({
+  sourceLocale,
+  targetLocales,
+  loadLocale: locale => {
+    if (!allLocales.includes(locale)) locale = 'en';
+    return import(
+        /* webpackMode: "eager" */
+        /* webpackExclude: /locales\.json$/ */
+        `../lit-locales/generated/${locale}.js`);
+  },
+});
diff --git a/src/contentScripts/communityConsole/flattenThreads/components/ReplyButton.js b/src/contentScripts/communityConsole/flattenThreads/components/ReplyButton.js
index a5bf48d..5dc7d59 100644
--- a/src/contentScripts/communityConsole/flattenThreads/components/ReplyButton.js
+++ b/src/contentScripts/communityConsole/flattenThreads/components/ReplyButton.js
@@ -1,12 +1,14 @@
 import '@material/web/button/outlined-button.js';
 
-import {css, html, LitElement} from 'lit';
+import {msg} from '@lit/localize';
+import {css, html} from 'lit';
 import {waitFor} from 'poll-until-promise';
 
+import {I18nLitElement} from '../../../../common/litI18nUtils.js';
 import {SHARED_MD3_STYLES} from '../../../../common/styles/md3.js';
 import {getExtraInfoNodes} from '../flattenThreads.js';
 
-export default class TwptFlattenThreadReplyButton extends LitElement {
+export default class TwptFlattenThreadReplyButton extends I18nLitElement {
   static properties = {
     extraInfo: {type: Object},
   };
@@ -29,7 +31,9 @@
   render() {
     return html`
       <md-outlined-button
-          label="Reply"
+          label="${msg('Reply', {
+            desc: 'Button which is used to open the reply box.',
+          })}"
           @click=${this.openReplyEditor}>
       </md-outlined-button>
     `;
diff --git a/src/contentScripts/communityConsole/flattenThreads/components/index.js b/src/contentScripts/communityConsole/flattenThreads/components/index.js
index bf532fb..39e8310 100644
--- a/src/contentScripts/communityConsole/flattenThreads/components/index.js
+++ b/src/contentScripts/communityConsole/flattenThreads/components/index.js
@@ -5,14 +5,16 @@
 // Other components imported so they are also injected:
 import './ReplyButton.js';
 
+import {msg} from '@lit/localize';
 import * as DOMPurify from 'dompurify';
-import {css, html, LitElement} from 'lit';
+import {css, html} from 'lit';
 import {classMap} from 'lit/directives/class-map.js';
 import {unsafeHTML} from 'lit/directives/unsafe-html.js';
 
+import {I18nLitElement} from '../../../../common/litI18nUtils.js';
 import {SHARED_MD3_STYLES} from '../../../../common/styles/md3.js';
 
-export default class TwptFlattenThreadQuote extends LitElement {
+export default class TwptFlattenThreadQuote extends I18nLitElement {
   static properties = {
     prevMessage: {type: Object},
     _expanded: {type: Boolean},
@@ -113,6 +115,12 @@
       'quote-container': true,
       'quote-container--expanded': this._expanded,
     });
+    const lessMsg = msg('Less', {
+      desc: 'Button to collapse the quote message (used in the flatten threads feature).',
+    });
+    const moreMsg = msg('More', {
+      desc: 'Button to expand the quote message (used in the flatten threads feature).',
+    });
     return html`
       <div class=${containerClasses}>
         <div class="payload-container">
@@ -126,7 +134,7 @@
         <div class="buttons-row">
           <md-tonal-button
               icon="${this._expanded ? 'expand_less' : 'expand_more'}"
-              label="${this._expanded ? 'Less' : 'More'}"
+              label="${this._expanded ? lessMsg : moreMsg}"
               @click=${this.toggleExpanded}>
           </md-tonal-button>
         </div>
diff --git a/src/lit-locales/generated/.gitignore b/src/lit-locales/generated/.gitignore
new file mode 100644
index 0000000..afe8be7
--- /dev/null
+++ b/src/lit-locales/generated/.gitignore
@@ -0,0 +1,2 @@
+*.js
+*.ts
diff --git a/src/lit-locales/generated/README b/src/lit-locales/generated/README
new file mode 100644
index 0000000..39b1d0d
--- /dev/null
+++ b/src/lit-locales/generated/README
@@ -0,0 +1,5 @@
+This folder contains modules autogenerated by `make lit_localize_build`, ran by
+webpack when serving/building the extension.
+
+Please, do not add any file to this folder other than this document and the
+.gitignore file.
diff --git a/src/lit-locales/source/ar.xlf b/src/lit-locales/source/ar.xlf
new file mode 100644
index 0000000..a029342
--- /dev/null
+++ b/src/lit-locales/source/ar.xlf
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+<file target-language="ar" source-language="en" original="lit-localize-inputs" datatype="plaintext">
+<body>
+<trans-unit id="s0b7ae9543c001867">
+  <source>Reply</source>
+  <note from="lit-localize">Button which is used to open the reply box.</note>
+</trans-unit>
+<trans-unit id="sa5ef80b4bb9b39f8">
+  <source>Less</source>
+  <note from="lit-localize">Button to collapse the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+<trans-unit id="s37a9e8aec5713460">
+  <source>More</source>
+  <note from="lit-localize">Button to expand the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+</body>
+</file>
+</xliff>
diff --git a/src/lit-locales/source/ca.xlf b/src/lit-locales/source/ca.xlf
new file mode 100644
index 0000000..bac628b
--- /dev/null
+++ b/src/lit-locales/source/ca.xlf
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+<file target-language="ca" source-language="en" original="lit-localize-inputs" datatype="plaintext">
+<body>
+<trans-unit id="s0b7ae9543c001867">
+  <source>Reply</source>
+  <note from="lit-localize">Button which is used to open the reply box.</note>
+</trans-unit>
+<trans-unit id="sa5ef80b4bb9b39f8">
+  <source>Less</source>
+  <note from="lit-localize">Button to collapse the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+<trans-unit id="s37a9e8aec5713460">
+  <source>More</source>
+  <note from="lit-localize">Button to expand the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+</body>
+</file>
+</xliff>
diff --git a/src/lit-locales/source/de.xlf b/src/lit-locales/source/de.xlf
new file mode 100644
index 0000000..fc2ac15
--- /dev/null
+++ b/src/lit-locales/source/de.xlf
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+<file target-language="de" source-language="en" original="lit-localize-inputs" datatype="plaintext">
+<body>
+<trans-unit id="s0b7ae9543c001867">
+  <source>Reply</source>
+  <note from="lit-localize">Button which is used to open the reply box.</note>
+</trans-unit>
+<trans-unit id="sa5ef80b4bb9b39f8">
+  <source>Less</source>
+  <note from="lit-localize">Button to collapse the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+<trans-unit id="s37a9e8aec5713460">
+  <source>More</source>
+  <note from="lit-localize">Button to expand the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+</body>
+</file>
+</xliff>
diff --git a/src/lit-locales/source/es.xlf b/src/lit-locales/source/es.xlf
new file mode 100644
index 0000000..feb09aa
--- /dev/null
+++ b/src/lit-locales/source/es.xlf
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+<file target-language="es" source-language="en" original="lit-localize-inputs" datatype="plaintext">
+<body>
+<trans-unit id="s0b7ae9543c001867">
+  <source>Reply</source>
+  <note from="lit-localize">Button which is used to open the reply box.</note>
+</trans-unit>
+<trans-unit id="sa5ef80b4bb9b39f8">
+  <source>Less</source>
+  <note from="lit-localize">Button to collapse the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+<trans-unit id="s37a9e8aec5713460">
+  <source>More</source>
+  <note from="lit-localize">Button to expand the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+</body>
+</file>
+</xliff>
diff --git a/src/lit-locales/source/fr.xlf b/src/lit-locales/source/fr.xlf
new file mode 100644
index 0000000..4bcddaf
--- /dev/null
+++ b/src/lit-locales/source/fr.xlf
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+<file target-language="fr" source-language="en" original="lit-localize-inputs" datatype="plaintext">
+<body>
+<trans-unit id="s0b7ae9543c001867">
+  <source>Reply</source>
+  <note from="lit-localize">Button which is used to open the reply box.</note>
+</trans-unit>
+<trans-unit id="sa5ef80b4bb9b39f8">
+  <source>Less</source>
+  <note from="lit-localize">Button to collapse the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+<trans-unit id="s37a9e8aec5713460">
+  <source>More</source>
+  <note from="lit-localize">Button to expand the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+</body>
+</file>
+</xliff>
diff --git a/src/lit-locales/source/id.xlf b/src/lit-locales/source/id.xlf
new file mode 100644
index 0000000..d305689
--- /dev/null
+++ b/src/lit-locales/source/id.xlf
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+<file target-language="id" source-language="en" original="lit-localize-inputs" datatype="plaintext">
+<body>
+<trans-unit id="s0b7ae9543c001867">
+  <source>Reply</source>
+  <note from="lit-localize">Button which is used to open the reply box.</note>
+</trans-unit>
+<trans-unit id="sa5ef80b4bb9b39f8">
+  <source>Less</source>
+  <note from="lit-localize">Button to collapse the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+<trans-unit id="s37a9e8aec5713460">
+  <source>More</source>
+  <note from="lit-localize">Button to expand the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+</body>
+</file>
+</xliff>
diff --git a/src/lit-locales/source/it.xlf b/src/lit-locales/source/it.xlf
new file mode 100644
index 0000000..ba1eb1a
--- /dev/null
+++ b/src/lit-locales/source/it.xlf
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+<file target-language="it" source-language="en" original="lit-localize-inputs" datatype="plaintext">
+<body>
+<trans-unit id="s0b7ae9543c001867">
+  <source>Reply</source>
+  <note from="lit-localize">Button which is used to open the reply box.</note>
+</trans-unit>
+<trans-unit id="sa5ef80b4bb9b39f8">
+  <source>Less</source>
+  <note from="lit-localize">Button to collapse the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+<trans-unit id="s37a9e8aec5713460">
+  <source>More</source>
+  <note from="lit-localize">Button to expand the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+</body>
+</file>
+</xliff>
diff --git a/src/lit-locales/source/ja.xlf b/src/lit-locales/source/ja.xlf
new file mode 100644
index 0000000..1e8d38e
--- /dev/null
+++ b/src/lit-locales/source/ja.xlf
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+<file target-language="ja" source-language="en" original="lit-localize-inputs" datatype="plaintext">
+<body>
+<trans-unit id="s0b7ae9543c001867">
+  <source>Reply</source>
+  <note from="lit-localize">Button which is used to open the reply box.</note>
+</trans-unit>
+<trans-unit id="sa5ef80b4bb9b39f8">
+  <source>Less</source>
+  <note from="lit-localize">Button to collapse the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+<trans-unit id="s37a9e8aec5713460">
+  <source>More</source>
+  <note from="lit-localize">Button to expand the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+</body>
+</file>
+</xliff>
diff --git a/src/lit-locales/source/ko.xlf b/src/lit-locales/source/ko.xlf
new file mode 100644
index 0000000..6a3d938
--- /dev/null
+++ b/src/lit-locales/source/ko.xlf
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+<file target-language="ko" source-language="en" original="lit-localize-inputs" datatype="plaintext">
+<body>
+<trans-unit id="s0b7ae9543c001867">
+  <source>Reply</source>
+  <note from="lit-localize">Button which is used to open the reply box.</note>
+</trans-unit>
+<trans-unit id="sa5ef80b4bb9b39f8">
+  <source>Less</source>
+  <note from="lit-localize">Button to collapse the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+<trans-unit id="s37a9e8aec5713460">
+  <source>More</source>
+  <note from="lit-localize">Button to expand the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+</body>
+</file>
+</xliff>
diff --git a/src/lit-locales/source/pl.xlf b/src/lit-locales/source/pl.xlf
new file mode 100644
index 0000000..8d1b568
--- /dev/null
+++ b/src/lit-locales/source/pl.xlf
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+<file target-language="pl" source-language="en" original="lit-localize-inputs" datatype="plaintext">
+<body>
+<trans-unit id="s0b7ae9543c001867">
+  <source>Reply</source>
+  <note from="lit-localize">Button which is used to open the reply box.</note>
+</trans-unit>
+<trans-unit id="sa5ef80b4bb9b39f8">
+  <source>Less</source>
+  <note from="lit-localize">Button to collapse the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+<trans-unit id="s37a9e8aec5713460">
+  <source>More</source>
+  <note from="lit-localize">Button to expand the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+</body>
+</file>
+</xliff>
diff --git a/src/lit-locales/source/pt_BR.xlf b/src/lit-locales/source/pt_BR.xlf
new file mode 100644
index 0000000..685d940
--- /dev/null
+++ b/src/lit-locales/source/pt_BR.xlf
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+<file target-language="pt_BR" source-language="en" original="lit-localize-inputs" datatype="plaintext">
+<body>
+<trans-unit id="s0b7ae9543c001867">
+  <source>Reply</source>
+  <note from="lit-localize">Button which is used to open the reply box.</note>
+</trans-unit>
+<trans-unit id="sa5ef80b4bb9b39f8">
+  <source>Less</source>
+  <note from="lit-localize">Button to collapse the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+<trans-unit id="s37a9e8aec5713460">
+  <source>More</source>
+  <note from="lit-localize">Button to expand the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+</body>
+</file>
+</xliff>
diff --git a/src/lit-locales/source/ru.xlf b/src/lit-locales/source/ru.xlf
new file mode 100644
index 0000000..7eaa9fc
--- /dev/null
+++ b/src/lit-locales/source/ru.xlf
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+<file target-language="ru" source-language="en" original="lit-localize-inputs" datatype="plaintext">
+<body>
+<trans-unit id="s0b7ae9543c001867">
+  <source>Reply</source>
+  <note from="lit-localize">Button which is used to open the reply box.</note>
+</trans-unit>
+<trans-unit id="sa5ef80b4bb9b39f8">
+  <source>Less</source>
+  <note from="lit-localize">Button to collapse the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+<trans-unit id="s37a9e8aec5713460">
+  <source>More</source>
+  <note from="lit-localize">Button to expand the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+</body>
+</file>
+</xliff>
diff --git a/src/lit-locales/source/th.xlf b/src/lit-locales/source/th.xlf
new file mode 100644
index 0000000..b13edb4
--- /dev/null
+++ b/src/lit-locales/source/th.xlf
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+<file target-language="th" source-language="en" original="lit-localize-inputs" datatype="plaintext">
+<body>
+<trans-unit id="s0b7ae9543c001867">
+  <source>Reply</source>
+  <note from="lit-localize">Button which is used to open the reply box.</note>
+</trans-unit>
+<trans-unit id="sa5ef80b4bb9b39f8">
+  <source>Less</source>
+  <note from="lit-localize">Button to collapse the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+<trans-unit id="s37a9e8aec5713460">
+  <source>More</source>
+  <note from="lit-localize">Button to expand the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+</body>
+</file>
+</xliff>
diff --git a/src/lit-locales/source/tr.xlf b/src/lit-locales/source/tr.xlf
new file mode 100644
index 0000000..c6468f2
--- /dev/null
+++ b/src/lit-locales/source/tr.xlf
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+<file target-language="tr" source-language="en" original="lit-localize-inputs" datatype="plaintext">
+<body>
+<trans-unit id="s0b7ae9543c001867">
+  <source>Reply</source>
+  <note from="lit-localize">Button which is used to open the reply box.</note>
+</trans-unit>
+<trans-unit id="sa5ef80b4bb9b39f8">
+  <source>Less</source>
+  <note from="lit-localize">Button to collapse the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+<trans-unit id="s37a9e8aec5713460">
+  <source>More</source>
+  <note from="lit-localize">Button to expand the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+</body>
+</file>
+</xliff>
diff --git a/src/lit-locales/source/vi.xlf b/src/lit-locales/source/vi.xlf
new file mode 100644
index 0000000..674c7dc
--- /dev/null
+++ b/src/lit-locales/source/vi.xlf
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
+<file target-language="vi" source-language="en" original="lit-localize-inputs" datatype="plaintext">
+<body>
+<trans-unit id="s0b7ae9543c001867">
+  <source>Reply</source>
+  <note from="lit-localize">Button which is used to open the reply box.</note>
+</trans-unit>
+<trans-unit id="sa5ef80b4bb9b39f8">
+  <source>Less</source>
+  <note from="lit-localize">Button to collapse the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+<trans-unit id="s37a9e8aec5713460">
+  <source>More</source>
+  <note from="lit-localize">Button to expand the quote message (used in the flatten threads feature).</note>
+</trans-unit>
+</body>
+</file>
+</xliff>