Skip to content

Commit

Permalink
Merge dc66a49 into c563956
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja committed Mar 1, 2022
2 parents c563956 + dc66a49 commit 4fc7b90
Show file tree
Hide file tree
Showing 17 changed files with 433 additions and 114 deletions.
16 changes: 16 additions & 0 deletions docs/locale/es/config.md.po
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,19 @@ msgstr ""
"Especifica como cadena terminada con `%` como `55%` para porcentaje de "
"mensajes totales o como entero como `76` para determinar el número mínimo de"
" mensajes traducidos requeridos para incluir un idioma."

msgid ""
"Exclude certain files from being translated, still creating copies of "
"original ones in target languages. Accepts relative paths to files from "
"`docs_dir` (documentation directory)."
msgstr ""
"Excluye ciertos archivos de ser traducidos, aún creando copias de los "
"archivos originales en los idiomas objetivo. Acepta rutas relativas a los "
"archivos desde el directorio `docs_dir` (directorio de documentación)."

msgid ""
"This setting is useful if you want, for example, to exclude a changelog file"
" from being translated."
msgstr ""
"Esta configuración es útil si quieres, por ejemplo, excluir un archivo de "
"historial de cambios o changelog de ser traducido."
14 changes: 12 additions & 2 deletions docs/src/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,23 @@ total messages or as an integer like `76` to determine the minimum
number of translated messages required to include a language.

<!-- mdpo-disable-next-line -->
### **`ignore_extensions`** (*list*)
### **`exclude`** (*list[str]*)

Exclude certain files from being translated, still creating copies of
original ones in target languages. Accepts relative paths to files from
`docs_dir` (documentation directory).

This setting is useful if you want, for example, to exclude a changelog
file from being translated.

<!-- mdpo-disable-next-line -->
### **`ignore_extensions`** (*list[str]*)

File extensions that are ignored from being added to site directory, defaults to
`['.po', '.pot', '.mo']`.

<!-- mdpo-disable-next-line -->
### **`ignore_msgids`** (*list*)
### **`ignore_msgids`** (*list[str]*)

You can ignore certain messages from being dumped into PO files adding them to
this list.
Expand Down
4 changes: 2 additions & 2 deletions docs/src/useful-recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ use them directly [as a command line interface][mdpo-cli] or through is

```yaml
- repo: https://github.com/mondeja/mdpo
rev: v0.3.84
rev: v0.3.85
hooks:
- id: md2po2md
files: ^README\.md
args: ['-l', 'es', '-l', 'fr', '-o', 'locale/{lang}']
args: ['-l', 'es', 'fr', '-o', 'locale/{lang}']
```
<!-- mdpo-include-codeblocks -->
=== "Directories tree"
Expand Down
6 changes: 6 additions & 0 deletions examples/exclude/docs/locale/es/do-not-translate.md.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
msgid ""
msgstr ""

msgid "Not translated"
msgstr "No traducida"
12 changes: 12 additions & 0 deletions examples/exclude/docs/locale/es/index.md.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
msgid ""
msgstr ""

msgid "Home"
msgstr "Inicio"

msgid "Welcome to MkDocs"
msgstr "Bienvenido a Mkdocs"

msgid "Some content"
msgstr "Algo de contenido"
6 changes: 6 additions & 0 deletions examples/exclude/docs/locale/fr/do-not-translate.md.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
msgid ""
msgstr ""

msgid "Not translated"
msgstr "Non traduit"
12 changes: 12 additions & 0 deletions examples/exclude/docs/locale/fr/index.md.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
msgid ""
msgstr ""

msgid "Home"
msgstr "Accueil"

msgid "Welcome to MkDocs"
msgstr "Bienvenue sur mkdocs"

msgid "Some content"
msgstr "Du contenu"
7 changes: 7 additions & 0 deletions examples/exclude/docs/src/changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

## version - date

- Feature A
- Feature B
- Bugfix A
3 changes: 3 additions & 0 deletions examples/exclude/docs/src/do-not-translate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- mdpo-disable -->

Some content that shouldn't be translated.
3 changes: 3 additions & 0 deletions examples/exclude/docs/src/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Welcome to MkDocs

Some content
20 changes: 20 additions & 0 deletions examples/exclude/mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
site_name: mkdocs-mdpo-plugin Mkdocs theme example
site_url: https://mkdocs-mdpo.ga
docs_dir: docs/src

nav:
- Home: index.md
- Changelog: changelog.md
- Not translated: do-not-translate.md

plugins:
- search
- mdpo:
languages:
- en
- es
- fr
cross_language_search: false
locale_dir: ../locale
exclude:
- changelog.md
18 changes: 18 additions & 0 deletions mkdocs_mdpo_plugin/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
('ignore_msgids', Type(list, default=[])),
('cross_language_search', Type(bool, default=True)),
('min_translated_messages', Type((str, int), default=None)),
('exclude', Type(list, default=[])),
)


Expand Down Expand Up @@ -191,6 +192,23 @@ def _languages_required():
else:
plugin.config['min_translated_messages'] = min_translated

# check that 'exclude' contains a valid list
exclude = plugin.config.get('exclude') or []
if not isinstance(exclude, list):
raise ValidationError(
'Expected mdpo\'s "exclude" setting to be a list, but found'
f' the value {str(exclude)} of type {type(exclude).__name__}',
)
else:
for i, path in enumerate(exclude):
if not isinstance(path, str):
raise ValidationError(
f'Expected mdpo\'s setting "exclude[{i}]" value to'
f' be a string, but found the value {str(path)} of'
f' type {type(path).__name__}',
)
plugin.config['exclude'] = exclude

# store reference in plugin to markdown_extensions for later usage
plugin.extensions.markdown = markdown_extensions

Expand Down
Loading

0 comments on commit 4fc7b90

Please sign in to comment.