Skip to content

Instantly share code, notes, and snippets.

@pavlin-policar
Last active August 29, 2015 14:25
Show Gist options
  • Save pavlin-policar/6715de793b4529458268 to your computer and use it in GitHub Desktop.
Save pavlin-policar/6715de793b4529458268 to your computer and use it in GitHub Desktop.
Moodle prepend lang tags where any translations are needed.
Long syntax:
Find:
(<span lang="es")
Replace:
<span lang="en" class="multilang">&nbsp;English version<\/span><span lang="sl" class="multilang">&nbsp;Slovenska verzija<\/span>$1
Short syntax:
Find:
(\{mlang es\})
Replace:
\{mlang en\}&nbsp;English version\{mlang\}\{mlang sl\}&nbsp;Slovenska verzija\{mlang\}$1
Moodle yes/no cloze question replace regex (see UNIT 3: Real numbers ex.2 as an example).
Find:
\{1:MC:(=)?Si~(=)?No\}
Replace:
\{1:MC:$1\{mlang en\\\}Yes\{mlang\\\}\{mlang sl\\\}Da\{mlang\\\}~$2\{mlang en\\\}No\{mlang\\\}\{mlang sl\\\}Ne\{mlang\\\}\}
Moodle yes/no questions already translated using above transform and change with shorter language syntax.
E.g.
<span lang="en" class="multilang">Yes</span>
-> (regular, works only with simple tags, DON'T run this on a whole document, as nested html elements will mess it up)
{mlang en}Yes{mlang}
-> (where closing curly brace must be escaped e.g. cloze question type)
{mlang en\}Yes{mlang\}
Find:
<span lang="(\w{2})" class="multilang">(\w+)<\/span>
Replace (regular, works only with simple tags, DON'T run this on a whole document, as nested html elements will mess it up):
\{mlang $1\}$2\{mlang\}
Replace (where closing curly brace must be escaped):
\{mlang $1\\\}$2\{mlang\\\}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment