Ver código fonte

fix: add translations to resource mapping

Sv443 4 meses atrás
pai
commit
120db714af
3 arquivos alterados com 15 adições e 7 exclusões
  1. 10 1
      assets/resources.json
  2. 4 3
      contributing.md
  3. 1 3
      src/utils/misc.ts

+ 10 - 1
assets/resources.json

@@ -51,6 +51,15 @@
     "img-greasyfork": "images/external/greasyfork.png",
     "img-logo_dev": "images/logo/logo_dev_48.png",
     "img-logo": "images/logo/logo_48.png",
-    "img-openuserjs": "images/external/openuserjs.png"
+    "img-openuserjs": "images/external/openuserjs.png",
+    "trans-de-DE": "translations/de-DE.json",
+    "trans-en-US": "translations/en-US.json",
+    "trans-en-GB": "translations/en-GB.json",
+    "trans-es-ES": "translations/es-ES.json",
+    "trans-fr-FR": "translations/fr-FR.json",
+    "trans-hi-IN": "translations/hi-IN.json",
+    "trans-ja-JP": "translations/ja-JP.json",
+    "trans-pt-BR": "translations/pt-BR.json",
+    "trans-zh-CN": "translations/zh-CN.json"
   }
 }

+ 4 - 3
contributing.md

@@ -52,8 +52,9 @@ To submit a translation, please follow these steps:
     1. Duplicate the `en-US.json` file in the folder [`assets/translations/`](./assets/translations/) by keeping the format `languageCode_localeCode.json`
     2. Edit it to your translated version and keep the left side of the colon unchanged
     3. Create the mapping in `assets/locales.json` by copying the English one and editing it (please make sure it's alphabetically ordered)
-    4. Add your name to the respective `authors` property in [`assets/locales.json`](./assets/locales.json)
-    5. Test your changes by following [this section](#setting-up-the-project-for-local-development), then submit your pull request
+    4. Add the path to the JSON file to `assets/resources.json` by following the format of the others and also alphabetical order
+    5. Add your name to the respective `authors` property in [`assets/locales.json`](./assets/locales.json)
+    6. Test your changes by following [this section](#setting-up-the-project-for-local-development), then submit your pull request
 7. Alternatively send it to me directly, [see my homepage](https://sv443.net/) for contact info  
   Make sure you also add your language to the contents of [`assets/locales.json`](./assets/locales.json)
 
@@ -204,7 +205,7 @@ If you need help with these, don't hesitate to reach out to me (see the top of t
   3. Add the asset to the [`assets/resources.json`](./assets/resources.json) file by following the format of the other entries.  
     If the path begins with a slash, it will start at the project root (where package.json is), otherwise it will start at the `assets` folder.  
     The path string or all values in the object of each resource will be passed through the function `resolveResourceVal()` in [`src/tools/post-build.ts`](./src/tools/post-build.ts) to resolve placeholders like `$BRANCH`. View all replacements by looking up that function.
-  4. The asset will be immediately available in the userscript after the next build and the `@resource` directive will automatically point at the locally served asset or the GitHub CDN, depending on the build mode.
+  4. The asset will be immediately available in the userscript after the next build and the `@resource` directive will automatically point at the locally served asset or the GitHub CDN, depending on the build mode and if the asset key matches a pattern in `alwaysExternalAssetPatterns` in the `assets/resources.json` file.
   5. **When committing, make sure to commit the assets first, then rebuild the userscript and make a second commit.**  
     This needs to be done because the build script at `src/tools/post-build.ts` will use the *previous* commit hash to create version-independent URLs for the assets. These will continue to work in the future, instead of pointing to an ever-changing branch where files could be moved, renamed or deleted at any time.
 - Adding a new site event:

+ 1 - 3
src/utils/misc.ts

@@ -255,8 +255,6 @@ export async function reloadTab() {
 
 //#region resources
 
-const alwaysExternalAssetRegexes = resourcesJson.alwaysExternalAssetPatterns.map(pat => new RegExp(pat));
-
 /**
  * Returns the blob-URL of a resource by its name, as defined in `assets/resources.json`, from GM resource cache - [see GM.getResourceUrl docs](https://wiki.greasespot.net/GM.getResourceUrl)  
  * Falls back to a `raw.githubusercontent.com` URL or base64-encoded data URI if the resource is not available in the GM resource cache  
@@ -273,7 +271,7 @@ export async function getResourceUrl(name: ResourceKey | "_", uncached = false)
       const pathName = typeof resObjOrStr === "object" && "path" in resObjOrStr ? resObjOrStr.path : resObjOrStr;
       const ghRef = typeof resObjOrStr === "object" && "ref" in resObjOrStr ? resObjOrStr.ref : buildNumber;
 
-      if(alwaysExternalAssetRegexes.some(re => re.test(name)) || (pathName?.startsWith("/") && pathName.length > 1))
+      if((pathName?.startsWith("/") && pathName.length > 1))
         return `https://raw.githubusercontent.com/${repo}/${ghRef}${pathName}`;
       else if(pathName && pathName.startsWith("http"))
         return pathName;