Skip to content

Commit

Permalink
Merge pull request #21 from voitau/master
Browse files Browse the repository at this point in the history
Save header from original file in localized file
  • Loading branch information
voitau authored Apr 5, 2020
2 parents 7fa2969 + edd3c9c commit 1008562
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 20 deletions.
11 changes: 9 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@

# Contributing

Thank you for your interest in contributing!

Any contribution is very welcome, including but not limited to:

* cleaning the Bash code, making it more portable across other shells and standard compliant.
* localizing the documentation.
* anything what you think is incorrect or missing here.

Bug report:

* please submit as an issue and provide steps to reproduce.

Coding style:

* please use 2 spaces indentation
* split into reasobly small functions
* use local variables

Code analysis
Code analysis:

* use shellcheck to perform static code analysis

Unit testing
Unit testing:

* all user facing commands and argument variations have to be unit tested with bats
* each command that has an input prompt, has to have an option to assume default value (e.g. --yes)
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ Minimal reference implenentation of [Markdown Localization Specification](https:

To install or update mdlm, you should run the install script. To do that, you may either download and run the script manually, or use the following cURL or Wget command:
```sh
curl -o- https://raw.githubusercontent.com/markdown-localization/mdlm-sh/v0.0.16/install.sh | bash
curl -o- https://raw.githubusercontent.com/markdown-localization/mdlm-sh/v0.0.17/install.sh | bash
```
```sh
wget -qO- https://raw.githubusercontent.com/markdown-localization/mdlm-sh/v0.0.16/install.sh | bash
wget -qO- https://raw.githubusercontent.com/markdown-localization/mdlm-sh/v0.0.17/install.sh | bash
```
Running either of the above commands downloads a script and runs it. The script copies mdlm script to `~/.mdlm`, and attempts to add the source lines from the snippet below to the correct profile file (`~/.bash_profile`, or `~/.bashrc`).

Expand All @@ -29,7 +29,7 @@ alias mdlm='$MDLM_DIR/mdlm.sh'

## List all supported locales

```
```console
$ mdlm search
aa (Afaraf) - Afar
ab (Аҧсуа) - Abkhazian
Expand All @@ -45,7 +45,7 @@ av (Авар) - Avaric

## List supported locales matching a specific pattern

```
```console
$ mdlm search uz
uz (Ўзбек) Uzbek
uz-Cyrl (Ўзбек) Uzbek in Cyrillic script
Expand All @@ -54,12 +54,12 @@ uz-Latn (O‘zbekcha) Uzbek in Latin script

## Add a new locale

```
```console
$ mdlm add eo
Creating new localization files for locale - "eo (Esperanto) - Esperanto":
Creating example/README-eo.md. Confirm? [Y/n]
Creating example/README-eo.md. Confirm? [Y/n]
- Created.
Creating README-eo.md. Confirm? [Y/n]
Creating README-eo.md. Confirm? [Y/n]
- Created.
Finished. Total files created: 2
```
Expand All @@ -68,7 +68,7 @@ As a result, new README-eo.md file will be created. Localization switcher header

## Remove a locale

```
```console
$ mdlm rm eo --yes
Removing localization files for locale - "eo (Esperanto) - Esperanto":
Removing README-eo.md.
Expand All @@ -78,11 +78,11 @@ Removing example/README-eo.md.
Localization files removed.
```

As a result, README-eo.md will be removed. Localization switcher header will be updated, or removed, if no other localizations available. Optional `--yes` automatically sets yes to all prompts.
As a result, README-eo.md will be removed. Localization switcher header will be updated, or removed, if no other localizations available. Optional `--yes` automatically sets yes to all prompts.

## Check synchronization status

```
```console
$ mdlm status
Localization status for all locales.
example/README.md (English):
Expand All @@ -95,18 +95,19 @@ README.md (English):
* README-ru.md (Русский) - synced.
```

### Get synchronization diff
## Get synchronization diff

Locale argument is optional.
```

```console
$ mdlm diff es
Localization status for: es (Español) - Spanish.
- example/README-es.md (Español) - outdated.
5c4,5
< Here is an outdated text of example.
---
> Here is a text of example.
>
>
```

# Contributing
Expand All @@ -115,4 +116,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md)

# Credits

Special thanks to [nvm-sh/nvm](https://github.com/nvm-sh/nvm) for inpsiration and specifics.
Special thanks to [nvm-sh/nvm](https://github.com/nvm-sh/nvm) for inpsiration and specifics.
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{ # this ensures the entire script is downloaded #

MDLM_VERSION="0.0.16"
MDLM_VERSION="0.0.17"
MDLM_REMOTE_FILE="https://raw.githubusercontent.com/markdown-localization/mdlm-sh/v${MDLM_VERSION}/mdlm.sh"

mdlm_echo() {
Expand Down
14 changes: 11 additions & 3 deletions mdlm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#
# Functions:
# - mdlm_* - custom functions.
MDLM_VERSION="0.0.16"
MDLM_VERSION="0.0.17"

DEFAULT_LCM_LOCAL="English"

Expand Down Expand Up @@ -130,8 +130,16 @@ mdlm_copy_original_to_localized_file() {
command echo "${HEADER}" > "${LCM_FILE}"
command grep -v "${MDLM_HEADER}" "${ORIG_FILE}" \
| sed -e "/$MDLM_IGNORE_START/,/$MDLM_IGNORE_END/d" \
| awk -v RS="(^|\n)#" -v popen="${MDLM_P_OPEN}" -v pclose="${MDLM_P_CLOSE}" -v ptbd="${MDLM_P_TBD}" \
'{ if ($0) print popen "\n#" $0 pclose "\n" ptbd "\n"}' >> "${LCM_FILE}"
| awk -v popen="${MDLM_P_OPEN}" -v pclose="${MDLM_P_CLOSE}" -v ptbd="${MDLM_P_TBD}" \
'BEGIN {
RS="(^|\n)#";
FS="\n";
}
{
if ($0) {
print popen "\n#" $0 pclose "\n\n#" $1 "\n\n" ptbd "\n"
}
}' >> "${LCM_FILE}"
}

mdlm_add_locale() {
Expand Down
6 changes: 6 additions & 0 deletions test/example-original/README-fr.md.en-it-fr.expected
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@

Here is a text of example.
l10n:p -->

## Example A

TBD

<!-- l10n:p
### References

Some references here.
l10n:p -->

### References

TBD

6 changes: 6 additions & 0 deletions test/example-original/README-it.md.en-it-fr.expected
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@

Here is a text of example.
l10n:p -->

## Example A

TBD

<!-- l10n:p
### References

Some references here.
l10n:p -->

### References

TBD

6 changes: 6 additions & 0 deletions test/example-original/README-it.md.en-it.expected
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@

Here is a text of example.
l10n:p -->

## Example A

TBD

<!-- l10n:p
### References

Some references here.
l10n:p -->

### References

TBD

1 change: 1 addition & 0 deletions test/test-add.bats
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ teardown() {
run diff "${ORIG_FILE}" "${ORIG_FILE_EXP_IT_FR}"
[ $status -eq 0 ]

diff "${LCM_FILE_IT}" "${LCM_FILE_IT_EXP_EN_IT_FR}"
run diff "${LCM_FILE_IT}" "${LCM_FILE_IT_EXP_EN_IT_FR}"
[ $status -eq 0 ]

Expand Down

0 comments on commit 1008562

Please sign in to comment.