[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [snowflake-webext/master] Remove redundancy when updating homepage strings



commit b074f1c1dee12d29254fc5c2a92d17c4b3a81562
Author: Arlo Breault <abreault@xxxxxxxxxxxxx>
Date:   Thu Feb 4 13:27:10 2021 -0500

    Remove redundancy when updating homepage strings
---
 make.js                             | 33 +++++++++++++++++++++++
 package-lock.json                   |  8 +++++-
 package.json                        |  3 ++-
 static/_locales/en_US/messages.json |  5 +---
 static/index.html                   | 52 +++++++++++--------------------------
 5 files changed, 58 insertions(+), 43 deletions(-)

diff --git a/make.js b/make.js
index 81a5b9b..1699e52 100755
--- a/make.js
+++ b/make.js
@@ -5,6 +5,7 @@
 var { writeFileSync, readFileSync, readdirSync, statSync } = require('fs');
 var { execSync, spawn } = require('child_process');
 var cldr = require('cldr');
+var domino = require('domino');
 
 // All files required.
 var FILES = [
@@ -94,6 +95,37 @@ var translatedLangs = function() {
   out += "\n};\n\n";
   return out;
 };
+
+// FIXME: This is duplicated from index.js and should be shared in some way
+var fill = function(n, func) {
+  switch(n.nodeType) {
+    case 1:  // Node.ELEMENT_NODE
+    {
+      const m = /^__MSG_([^_]*)__$/.exec(n.getAttribute('data-msgid'));
+      if (m) {
+        var val = func(m[1]);
+        if (val != undefined) {
+          n.innerHTML = val;
+        }
+      }
+      n.childNodes.forEach(c => fill(c, func));
+      break;
+    }
+  }
+};
+
+var fillIndex = function(outDir) {
+  var indexFile = `${outDir}/index.html`;
+  var html = readFileSync(indexFile, 'utf8');
+  var dom = domino.createDocument(html);
+  var locales = require(`./static/_locales/en_US/messages.json`);
+  fill(dom.body, function(m) {
+    return locales[m].message;
+  });
+  html = dom.serialize();
+  writeFileSync(indexFile, html, 'utf8');
+};
+
 var tasks = new Map();
 
 var task = function(key, msg, func) {
@@ -136,6 +168,7 @@ task('build', 'build the snowflake proxy', function() {
   concatJS(outDir, 'badge', 'embed.js', availableLangs());
   writeFileSync(`${outDir}/index.js`, translatedLangs(), 'utf8');
   execSync(`cat ${STATIC}/index.js >> ${outDir}/index.js`);
+  fillIndex(outDir);
   console.log('Snowflake prepared.');
 });
 
diff --git a/package-lock.json b/package-lock.json
index 06d86d5..2b07ee3 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
 {
   "name": "snowflake-pt",
-  "version": "0.5.2",
+  "version": "0.5.3",
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {
@@ -299,6 +299,12 @@
         "webidl-conversions": "^4.0.2"
       }
     },
+    "domino": {
+      "version": "2.1.6",
+      "resolved": "https://registry.npmjs.org/domino/-/domino-2.1.6.tgz";,
+      "integrity": "sha512-3VdM/SXBZX2omc9JF9nOPCtDaYQ67BGp5CoLpIQlO2KCAPETs8TcDHacF26jXadGbvUteZzRTeos2fhID5+ucQ==",
+      "dev": true
+    },
     "emoji-regex": {
       "version": "8.0.0",
       "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz";,
diff --git a/package.json b/package.json
index 2a28ca8..eccee94 100644
--- a/package.json
+++ b/package.json
@@ -23,6 +23,7 @@
   "author": "Serene Han",
   "license": "BSD-3-Clause",
   "devDependencies": {
+    "domino": "^2.1.6",
     "eslint": "^6.0.1",
     "jasmine": "2.5.2"
   },
@@ -32,4 +33,4 @@
     "ws": "^3.3.1",
     "xmlhttprequest": "^1.8.0"
   }
-}
\ No newline at end of file
+}
diff --git a/static/_locales/en_US/messages.json b/static/_locales/en_US/messages.json
index 844aeff..8cda126 100644
--- a/static/_locales/en_US/messages.json
+++ b/static/_locales/en_US/messages.json
@@ -36,10 +36,7 @@
     "message": "Cookies are not enabled."
   },
   "websiteIntro": {
-    "message": "Snowflake is a system to defeat internet censorship. People who are censored can use Snowflake to access the internet. Their connection goes through Snowflake proxies, which are run by volunteers. For more detailed information about how Snowflake works see our <a href=\"https://trac.torproject.org/projects/tor/wiki/doc/Snowflake/\"; data-msgid=\"__MSG_docWiki__\">documentation wiki</a>."
-  },
-  "docWiki": {
-    "message": "documentation wiki"
+    "message": "Snowflake is a system to defeat internet censorship. People who are censored can use Snowflake to access the internet. Their connection goes through Snowflake proxies, which are run by volunteers. For more detailed information about how Snowflake works see our <a href=\"https://trac.torproject.org/projects/tor/wiki/doc/Snowflake/\";>documentation wiki</a>."
   },
   "browser": {
     "message": "Browser"
diff --git a/static/index.html b/static/index.html
index 4902c86..439574b 100644
--- a/static/index.html
+++ b/static/index.html
@@ -32,40 +32,31 @@
 
         <p class="diagram"><img src="./snowflake-schematic.png" alt="Diagram" /></p>
 
-        <p data-msgid="__MSG_websiteIntro__">Snowflake is a system to defeat internet censorship. People who are
-        censored can use Snowflake to access the internet. Their connection goes
-        through Snowflake proxies, which are run by volunteers. For more detailed
-        information about how Snowflake works see our
-        <a href="https://trac.torproject.org/projects/tor/wiki/doc/Snowflake/"; data-msgid="__MSG_docWiki__">documentation wiki</a>.</p>
+        <p data-msgid="__MSG_websiteIntro__"></p>
 
         <div class="sidebyside">
 
           <section id="browser" class="browser">
-            <h2 data-msgid="__MSG_browser__">Browser</h2>
+            <h2 data-msgid="__MSG_browser__"></h2>
 
-            <p data-msgid="__MSG_censoredUsers__">If your internet access is censored, you should download 
-            <a href="https://www.torproject.org/download/";>Tor Browser</a>.</p>
+            <p data-msgid="__MSG_censoredUsers__"></p>
 
             <p class="screenshot"><img src="./screenshot.png" alt="Tor Browser screenshot" /></p>
           </section>
 
           <section id="extension" class="extension">
-            <h2 data-msgid="__MSG_extension__">Extension</h2>
+            <h2 data-msgid="__MSG_extension__"></h2>
 
-            <p data-msgid="__MSG_installExtension__">If your internet access is <strong>not</strong> censored, you should
-            consider installing the Snowflake extension to help users in censored
-            networks. There is no need to worry about which websites people are
-            accessing through your proxy. Their visible browsing IP address will
-            match their Tor exit node, not yours.</p>
+            <p data-msgid="__MSG_installExtension__"></p>
 
             <p class="addon">
             <a href="https://addons.mozilla.org/en-US/firefox/addon/torproject-snowflake/";>
               <img src="./200px-Firefox_logo.png" alt="Install in Firefox" height="100" /><br />
-              <span data-msgid="MSG_installFirefox__">Install in Firefox</span>
+              <span data-msgid="__MSG_installFirefox__"></span>
             </a>
             <a href="https://chrome.google.com/webstore/detail/snowflake/mafpmfcccpbjnhfhjnllmmalhifmlcie";>
               <img src="./200px-Chrome_logo.png" alt="Install in Chrome" height="100" /><br />
-              <span data-msgid="__MSG_installChrome__">Install in Chrome</span>
+              <span data-msgid="__MSG_installChrome__"></span>
             </a>
             </p>
           </section>
@@ -73,39 +64,26 @@
         </div>
 
         <section id="bugs">
-          <h2 data-msgid="__MSG_reportingBugs__">Reporting Bugs</h2>
+          <h2 data-msgid="__MSG_reportingBugs__"></h2>
 
-          <p data-msgid="__MSG_fileBug__">If you encounter problems with Snowflake as a client or a proxy,
-          please consider filing a bug report.  There are two ways to file a bug report:</p>
+          <p data-msgid="__MSG_fileBug__"></p>
 
           <ol>
-            <li data-msgid="__MSG_bugTracker__">
-              <a href="https://gitlab.onionize.space/";>Request an account</a>
-              at the Tor Project GitLab, then
-              <a href="https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/issues";>open a new issue</a>
-              in the Snowflake project.
-            </li>
-            <li data-msgid="__MSG_sharedAccount__">
-              File an
-              <a href="https://anonticket.onionize.space/";>anonymous ticket</a>
-              by generating an identifier and logging in with it.  Then, find the Snowflake project in the List of all projects and create a new issue.
-            </li>
+            <li data-msgid="__MSG_bugTracker__"></li>
+            <li data-msgid="__MSG_sharedAccount__"></li>
           </ol>
 
-          <p data-msgid="__MSG_descriptive__">
-          Please try to be as descriptive as possible with your ticket and if
-          possible include log messages that will help us reproduce the bug.
-          </p>
+          <p data-msgid="__MSG_descriptive__"></p>
         </section>
 
         <section id="embed">
-          <h2 data-msgid="__MSG_embed__">Embed</h2>
+          <h2 data-msgid="__MSG_embed__"></h2>
 
-          <p data-msgid="__MSG_possible__">It is now possible to embed the Snowflake badge on any website:</p>
+          <p data-msgid="__MSG_possible__"></p>
 
           <textarea readonly>&lt;iframe src="https://snowflake.torproject.org/embed.html"; width="320" height="240" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;</textarea>
 
-          <p data-msgid="__MSG_looksLike__">Which looks like this:</p>
+          <p data-msgid="__MSG_looksLike__"></p>
 
           <iframe src="https://snowflake.torproject.org/embed.html"; width="320" height="240" frameborder="0" scrolling="no"></iframe>
         </section>



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits