Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea - Patterns for replacement #1

Open
SphinxKnight opened this issue Aug 4, 2022 · 0 comments
Open

Idea - Patterns for replacement #1

SphinxKnight opened this issue Aug 4, 2022 · 0 comments

Comments

@SphinxKnight
Copy link

Hi there :)

I'm no Sublime Text user but one thing that I often use while working on updates/new translations is https://marketplace.visualstudio.com/items?itemName=bhughes339.replacerules to replace patterns.
This helps consistently and effortlessly translating "standard" headers (like "See also", "Browser compatibility" etc.

I also use this one to replace "xref"-macros (though I don't properly deal with some edge cases at the moment).

Here is the current list of regexp/patterns (in French of course ^^):

"replacerules.rules": {
    "domxref-1-simple":{
        "find": "\\{\\{domxref\\(['\"]([^,.'\"]*?)['\"]\\)\\}\\}",
        "replace": "<a href=\"/fr/docs/Web/API/$1\"><code>$1</code></a>",
        "flags": "gmi"
    },
    "domxref-1-prop":{
        "find": "\\{\\{domxref\\(['\"]([^,.'\"]*?)\\.([^,.'\"]*?)['\"]\\)\\}\\}",
        "replace": "<a href=\"/fr/docs/Web/API/$1/$2\"><code>$1.$2</code></a>",
        "flags": "gmi"
    },
    "domxref-2-prop":{
        "find": "\\{\\{domxref\\(['\"]([^,.'\"]*?)\\.([^,.'\"]*?)['\"],[ ]?['\"]([^\"]*?)['\"]\\)\\}\\}",
        "replace": "<a href=\"/fr/docs/Web/API/$1/$2\"><code>$3</code></a>",
        "flags": "gmi"
    },
    "domxref-4-no-prop":{
        "find": "\\{\\{domxref\\(['\"]([^,.'\"]*?)['\"],[ ]?['\"]([^\"]*?)['\"],[ ]?['\"]['\"],[ ]?1\\)\\}\\}",
        "replace": "<a href=\"/fr/docs/Web/API/$1\">$2</a>",
        "flags": "gmi"
    },
    "domxref-4-prop":{
        "find": "\\{\\{domxref\\(['\"]([^,.'\"]*?)\\.([^,.'\"]*?)['\"],[ ]?['\"]([^\"]*?)['\"],[ ]?['\"]['\"],[ ]?1\\)\\}\\}",
        "replace": "<a href=\"/fr/docs/Web/API/$1/$2\">$3</a>",
        "flags": "gmi"
    },
    "http-header":{
        "find": "\\{\\{HTTPHeader\\(['\"]([^,.'\"]*?)['\"]\\)\\}\\}",
        "replace": "<a href=\"/fr/docs/Web/HTTP/Headers/$1\"><code>$1</code></a>",
        "flags": "gmi"
    },
    "http-method":{
        "find": "\\{\\{HTTPMethod\\(['\"]([^,.'\"]*?)['\"]\\)\\}\\}",
        "replace": "<a href=\"/fr/docs/Web/HTTP/Methods/$1\"><code>$1</code></a>",
        "flags": "gmi"
    },
    "http-status":{
        "find": "\\{\\{HTTPStatus\\(['\"]([^,.'\"]*?)['\"]\\)\\}\\}",
        "replace": "<a href=\"/fr/docs/Web/HTTP/Status/$1\"><code>$1</code></a>",
        "flags": "gmi"
    },
    "glossary-1":{
        "find": "\\{\\{Glossary\\(['\"]([^,.'\"]*?)['\"]\\)\\}\\}",
        "replace": "<a href=\"/fr/docs/Glossary/$1\">$1</a>",
        "flags": "gmi"
    },
    "glossary-2":{
        "find": "\\{\\{Glossary\\(['\"]([^,.'\"]*?)['\"],[ ]?['\"]([^\"]*?)['\"]\\)\\}\\}",
        "replace": "<a href=\"/fr/docs/Glossary/$1\">$2</a>",
        "flags": "gmi"
    },
    "htmlattrxref-1":{
        "find": "\\{\\{htmlattrxref\\(['\"]([^,.'\"]*?)['\"]\\)\\}\\}",
        "replace":"<a href=\"/fr/docs/Web/HTML/Global_attributes#$1\"><code>$1</code></a>",
        "flags": "gmi"
    },
    "htmlattrxref-2":{
        "find": "\\{\\{htmlattrxref\\(['\"]([^,.'\"]*?)['\"],[ ]?['\"]([^\"]*?)['\"]\\)\\}\\}",
        "replace":"<a href=\"/fr/docs/Web/HTML/Element/$2#attr-$1\"><code>$1</code></a>",
        "flags": "gmi"
    },
    "htmlattrxref-3":{
        "find": "\\{\\{htmlattrxref\\(['\"]([^,.'\"]*?)['\"],[ ]?['\"]([^\"]*?)['\"],[ ]?['\"]([^\"]*?)['\"]\\)\\}\\}",
        "replace":"<a href=\"/fr/docs/Web/HTML/Element/$2#attr-$1\"><code>$3</code></a>",
        "flags": "gmi"
    },
    "cssxref-1":{
        "find": "\\{\\{cssxref\\(['\"]([^,.'\"]*?)['\"]\\)\\}\\}",
        "replace":"<a href=\"/fr/docs/Web/CSS/$1\"><code>$1</code></a>",
        "flags": "gmi"
    },
    "htmlelement-1":{
        "find": "\\{\\{htmlelement\\(['\"]([^,.'\"]*?)['\"]\\)\\}\\}",
        "replace":"<a href=\"/fr/docs/Web/HTML/Element/$1\"><code>&lt;$1&gt;</code></a>",
        "flags": "gmi"
    },
    "event-1":{
        "find": "\\{\\{event\\(['\"]([^,.'\"]*?)['\"]\\)\\}\\}",
        "replace": "<a href=\"/fr/docs/Web/API/Document/$1_event\"><code>$1</code></a>",
        "flags": "gmi"
    },
    "jsxref-2-proto":{
        "find": "\\{\\{jsxref\\(['\"]([^,.'\"]*?)\\.prototype\\.([^,.'\"]*?)['\"],[ ]?['\"]([^\"]*?)['\"]\\)\\}\\}",
        "replace": "<a href=\"/fr/docs/Web/JavaScript/Reference/Global_Objects/$1/$2\"><code>$3</code></a>",
        "flags": "gmi"
    },
    "jsxref-1-proto":{
        "find": "\\{\\{jsxref\\(['\"]([^,.'\"]*?)\\.prototype\\.([^,.'\"]*?)['\"]\\)\\}\\}",
        "replace": "<a href=\"/fr/docs/Web/JavaScript/Reference/Global_Objects/$1/$2\"><code>$1.prototype.$2</code></a>",
        "flags": "gmi"
    },
    "jsxref-2-childpage":{
        "find": "\\{\\{jsxref\\(['\"]([^,.'\"]*?)\/([^,.'\"]*?)['\"],[ ]?['\"]([^\"]*?)['\"]\\)\\}\\}",
        "replace": "<a href=\"/fr/docs/Web/JavaScript/Reference/$1/$2\"><code>$3</code></a>",
        "flags": "gmi"
    },
    "jsxref-1":{
        "find": "\\{\\{jsxref\\(['\"]([^,.'\"]*?)['\"]\\)\\}\\}",
        "replace": "<a href=\"/fr/docs/Web/JavaScript/Reference/Global_Objects/$1\"><code>$1</code></a>",
        "flags": "gmi"
    },
    "SVGElement-1":{
        "find": "\\{\\{SVGElement\\(['\"]([^,.'\"]*?)['\"]\\)\\}\\}",
        "replace": "<a href=\"/fr/docs/Web/SVG/Element/$1\"><code>&lt;$1&gt;</code></a>",
        "flags": "gmi"
    },
    "SVGAttr-1":{
        "find": "\\{\\{SVGAttr\\(['\"]([^,.'\"]*?)['\"]\\)\\}\\}",
        "replace": "<a href=\"/fr/docs/Web/SVG/Attribute/$1\"><code>$1</code></a>",
        "flags": "gmi"
    },
    "bug-1":{
        "find": "\\{\\{bug\\(['\"]([^,.'\"]*?)['\"]\\)\\}\\}",
        "replace": "<a href=\"https://bugzilla.mozilla.org/show_bug.cgi?id=$1\">bug $1</a>",
        "flags": "gmi"
        
    },
    "ARIARole-1":{
        "find": "\\{\\{ARIARole\\(['\"]([^,.'\"]*?)['\"]\\)\\}\\}",
        "replace": "<a href=\"https://w3c.github.io/aria/#$1\"><code>$1</code></a>",
        "flags": "gmi"
    },
    "htmlattrdef-1":{
        "find": "\\{\\{htmlattrdef\\(['\"]([^,.'\"]*?)['\"]\\)\\}\\}",
        "replace": "<strong id=\"attr-$1\"><code>$1</code></strong>",
        "flags": "gmi"
    },
    "md-jsxref-2-proto":{
        "find": "\\{\\{jsxref\\(['\"]([^,.'\"]*?)\\.prototype\\.([^,.'\"]*?)['\"],[ ]?['\"]([^\"]*?)['\"]\\)\\}\\}",
        "replace": "[`$3`](/fr/docs/Web/JavaScript/Reference/Global_Objects/$1/$2)",
        "flags": "gmi"
    },
    "md-jsxref-1-proto":{
        "find": "\\{\\{jsxref\\(['\"]([^,.'\"]*?)\\.prototype\\.([^,.'\"]*?)['\"]\\)\\}\\}",
        "replace": "[`$1.prototype.$2`](/fr/docs/Web/JavaScript/Reference/Global_Objects/$1/$2)",
        "flags": "gmi"
    },
    "md-jsxref-1-prop":{
        "find": "\\{\\{jsxref\\(['\"]([^,.'\"]*?)\\.([^,.'\"]*?)['\"]\\)\\}\\}",
        "replace": "[`$1.$2`](/fr/docs/Web/JavaScript/Reference/Global_Objects/$1/$2)",
        "flags": "gmi"
    },
    "md-jsxref-2-prop":{
        "find": "\\{\\{jsxref\\(['\"]([^,.'\"]*?)\\.([^,.'\"]*?)['\"],[ ]?['\"]([^\"]*?)['\"]\\)\\}\\}",
        "replace": "[`$3`](/fr/docs/Web/JavaScript/Reference/Global_Objects/$1/$2)",
        "flags": "gmi"
    },
    "md-jsxref-2-childpage":{
        "find": "\\{\\{jsxref\\(['\"]([^,.'\"]*?)\/([^,.'\"]*?)['\"],[ ]?['\"]([^\"]*?)['\"]\\)\\}\\}",
        "replace": "[`$3`](/fr/docs/Web/JavaScript/Reference/$1/$2)",
        "flags": "gmi"
    },
    "md-jsxref-1":{
        "find": "\\{\\{jsxref\\(['\"]([^,.'\"]*?)['\"]\\)\\}\\}",
        "replace": "[`$1`](/fr/docs/Web/JavaScript/Reference/Global_Objects/$1)",
        "flags": "gmi"
    },
    "md-domxref-1-simple":{
        "find": "\\{\\{domxref\\(['\"]([^,.'\"]*?)['\"]\\)\\}\\}",
        "replace": "[`$1`](/fr/docs/Web/API/$1)",
        "flags": "gmi"
    },
    "md-domxref-1-prop":{
        "find": "\\{\\{domxref\\(['\"]([^,.'\"]*?)\\.([^,.'\"]*?)['\"]\\)\\}\\}",
        "replace": "[`$1.$2`](/fr/docs/Web/API/$1/$2)",
        "flags": "gmi"
    },
    "md-domxref-2-prop":{
        "find": "\\{\\{domxref\\(['\"]([^,.'\"]*?)\\.([^,.'\"]*?)['\"],[ ]?['\"]([^\"]*?)['\"]\\)\\}\\}",
        "replace": "[`$3`](/fr/docs/Web/API/$1/$2)",
        "flags": "gmi"
    },
    "md-domxref-4-no-prop":{
        "find": "\\{\\{domxref\\(['\"]([^,.'\"]*?)['\"],[ ]?['\"]([^\"]*?)['\"],[ ]?['\"]['\"],[ ]?1\\)\\}\\}",
        "replace": "[`$2`](/fr/docs/Web/API/$1)",
        "flags": "gmi"
    },
    "md-domxref-4-prop":{
        "find": "\\{\\{domxref\\(['\"]([^,.'\"]*?)\\.([^,.'\"]*?)['\"],[ ]?['\"]([^\"]*?)['\"],[ ]?['\"]['\"],[ ]?1\\)\\}\\}",
        "replace": "[`$3`](/fr/docs/Web/API/$1/$2)",
        "flags": "gmi"
    },
    "md-cssxref-1":{
        "find": "\\{\\{cssxref\\(['\"]([^,.'\"]*?)['\"]\\)\\}\\}",
        "replace":"[`$1`](/fr/docs/Web/CSS/$1)",
        "flags": "gmi"
    },
    "md-htmlelement-1":{
        "find": "\\{\\{htmlelement\\(['\"]([^,.'\"]*?)['\"]\\)\\}\\}",
        "replace":"[`<$1>`](/fr/docs/Web/HTML/Element/$1)",
        "flags": "gmi"
    },
    "md-heading-example":{
        "find": "## Examples",
        "replace":"## Exemples",
        "flags": "gmi"
    },
    "md-heading-browser-compat":{
        "find": "## Browser compatibility",
        "replace":"## Compatibilité des navigateurs",
        "flags": "gmi"
    },
    "md-heading-spec":{
        "find": "## Specifications",
        "replace":"## Spécifications",
        "flags": "gmi"
    },
    "md-heading-see-also":{
        "find": "## See also",
        "replace":"## Voir aussi",
        "flags": "gmi"
    },
    "md-heading-param":{
        "find": "## Parameters",
        "replace":"## Paramètres",
        "flags": "gmi"
    },
    "md-heading-return":{
        "find": "## Return value",
        "replace":"## Valeur de retour",
        "flags": "gmi"
    },
    "md-httpheader-1":{
        "find": "\\{\\{httpheader\\(['\"]([^,.'\"]*?)['\"]\\)\\}\\}",
            "replace":"[`$1`](/fr/docs/Web/HTTP/Headers/$1)",
            "flags": "gmi"
    },
    "md-svgattr-1":{
        "find": "\\{\\{svgattr\\(['\"]([^,.'\"]*?)['\"]\\)\\}\\}",
            "replace":"[`$1`](/fr/docs/Web/SVG/Attribute/$1)",
            "flags": "gmi"
    },
    "md-svgelement-1":{
        "find": "\\{\\{svgelement\\(['\"]([^,.'\"]*?)['\"]\\)\\}\\}",
            "replace":"[`<$1>`](/fr/docs/Web/SVG/Element/$1)",
            "flags": "gmi"
    },
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant