Skip to content

Commit a634a71

Browse files
committed
vue-gettext 2 for Vue.js 2
1 parent 49592e9 commit a634a71

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2269
-1233
lines changed

.babelrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": ["es2015"],
3+
"plugins": ["transform-runtime"],
4+
"comments": false
5+
}

.eslintrc

-19
This file was deleted.

.eslintrc.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// http://eslint.org/docs/user-guide/configuring
2+
3+
module.exports = {
4+
5+
root: true,
6+
7+
'env': {
8+
'mocha': true, // Used for unit tests.
9+
},
10+
11+
'globals': {
12+
'expect': true, // Used for unit tests.
13+
'sinon': true, // Used for unit tests.
14+
},
15+
16+
parserOptions: {
17+
sourceType: 'module'
18+
},
19+
20+
extends: 'standard',
21+
22+
plugins: [
23+
24+
// Required to lint *.vue files.
25+
// https://github.com/BenoitZugmeyer/eslint-plugin-html/tree/40c728#usage
26+
'html',
27+
28+
],
29+
30+
rules: {
31+
32+
// Require or disallow trailing commas http://eslint.org/docs/rules/comma-dangle
33+
'comma-dangle': ['error', 'always-multiline'],
34+
35+
// Limit multiple empty lines http://eslint.org/docs/rules/no-multiple-empty-lines
36+
'no-multiple-empty-lines': ['error', { 'max': 2 }],
37+
38+
// Disable padding within blocks http://eslint.org/docs/rules/padded-blocks.html
39+
'padded-blocks': 'off',
40+
41+
}
42+
43+
}

Makefile

+17-9
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ NODE_BINDIR = ./node_modules/.bin
44
export PATH := $(NODE_BINDIR):$(PATH)
55

66
# Where to write the files generated by this makefile.
7-
OUTPUT_DIR = example
7+
OUTPUT_DIR = dev
88

99
# Available locales for the app.
1010
LOCALES = en_GB fr_FR it_IT
1111

1212
# Name of the generated .po files for each available locale.
13-
LOCALE_FILES ?= $(patsubst %,example/locale/%/LC_MESSAGES/app.po,$(LOCALES))
13+
LOCALE_FILES ?= $(patsubst %,$(OUTPUT_DIR)/locale/%/LC_MESSAGES/app.po,$(LOCALES))
1414

1515
GETTEXT_HTML_SOURCES = $(shell find $(OUTPUT_DIR) -name '*.vue' -o -name '*.html' 2> /dev/null)
1616
GETTEXT_JS_SOURCES = $(shell find $(OUTPUT_DIR) -name '*.vue' -o -name '*.js')
@@ -23,25 +23,33 @@ clean:
2323

2424
makemessages: /tmp/template.pot
2525

26-
translations: ./example/translations.json
26+
translations: ./$(OUTPUT_DIR)/translations.json
2727

2828
# Create a main .pot template, then generate .po files for each available language.
29+
# Thanx to Systematic: https://github.com/Polyconseil/systematic/blob/866d5a/mk/main.mk#L167-L183
2930
/tmp/template.pot: $(GETTEXT_HTML_SOURCES)
31+
# `dir` is a Makefile built-in expansion function which extracts the directory-part of `$@`.
32+
# `$@` is a Makefile automatic variable: the file name of the target of the rule.
33+
# => `mkdir -p /tmp/`
3034
mkdir -p $(dir $@)
3135
which gettext-extract
36+
# Extract gettext strings from templates files and create a POT dictionary template.
3237
gettext-extract --quiet --output $@ $(GETTEXT_HTML_SOURCES)
33-
xgettext --language=JavaScript --keyword=i18n --keyword=npgettext:1c,2,3 \
34-
--from-code=utf-8 --sort-output --join-existing --no-wrap \
38+
# Extract gettext strings from JavaScript files.
39+
xgettext --language=JavaScript --keyword=npgettext:1c,2,3 \
40+
--from-code=utf-8 --join-existing --no-wrap \
41+
--package-name=$(shell node -e "console.log(require('./package.json').name);") \
3542
--package-version=$(shell node -e "console.log(require('./package.json').version);") \
3643
--output $@ $(GETTEXT_JS_SOURCES)
44+
# Generate .po files for each available language.
3745
@for lang in $(LOCALES); do \
3846
export PO_FILE=$(OUTPUT_DIR)/locale/$$lang/LC_MESSAGES/app.po; \
39-
echo "msgmerge --sort-output --update $$PO_FILE $@"; \
47+
echo "msgmerge --update $$PO_FILE $@"; \
4048
mkdir -p $$(dirname $$PO_FILE); \
41-
[ -f $$PO_FILE ] && msgmerge --lang=$$lang --sort-output --update $$PO_FILE $@ || msginit --no-translator --locale=$$lang --input=$@ -o $$PO_FILE; \
42-
msgattrib --no-wrap --no-location --no-obsolete -o $$PO_FILE $$PO_FILE; \
49+
[ -f $$PO_FILE ] && msgmerge --lang=$$lang --update $$PO_FILE $@ || msginit --no-translator --locale=$$lang --input=$@ --output-file=$$PO_FILE; \
50+
msgattrib --no-wrap --no-obsolete -o $$PO_FILE $$PO_FILE; \
4351
done;
4452

45-
$(OUTPUT_DIR)/translations.json: /tmp/template.pot
53+
$(OUTPUT_DIR)/translations.json: clean /tmp/template.pot
4654
mkdir -p $(OUTPUT_DIR)
4755
gettext-compile --output $@ $(LOCALE_FILES)

0 commit comments

Comments
 (0)