Skip to content

Commit

Permalink
replaced all language options by a uniformized -l, --lang option
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlath committed Aug 27, 2016
1 parent b3fab83 commit d25724f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,17 @@ wd wikiqid Cantabria
wd wikiqid New Delhi
# => Q987
```
By default, it will look at the Wikipedia corresponding to your environment local language (`process.env.LANG`), but you can specify another language by passing a 2-letters language code as last argument

**Options**

* `-l, --lang`: specify from which language the title comes
By default, it will look at the Wikipedia corresponding to your environment local language (`process.env.LANG`), but you can specify another language by passing a 2-letters language code
```sh
wd wikiqid science politique fr
wd wikiqid -l fr science politique
# => Q36442
```

You can also pass it full Wikipedia urls
You can also pass it full Wikipedia urls and let it find the language from there
```sh
wd wikiqid https://en.wikipedia.org/wiki/Friedrich_Nietzsche
# => Q9358
Expand All @@ -111,9 +115,11 @@ Output a JSON object of the kind:
NB: properties without a label in the requested language are set to `null`, as you can see above for P2898 in French

* Get the list of all Wikidata properties in another language
**Options**
* `-l, --lang`: specify the properties labels language
```sh
# here swedish
wd props sv
wd props -l sv
# outputs the properties in Swedish
```

This command first tries to find the list in the `props` folder (created at wikidata-cli root), and request them to query.wikidata.org if missing.
Expand Down Expand Up @@ -162,10 +168,12 @@ wd open https://inventaire.io/entity/wd:Q33977

**Options**
* `-p, --wikipedia`: open the Wiki**p**edia article instead
* `-l, --lang`: specify
```sh
wd open -p Q123
# opens https://fr.wikipedia.org/wiki/Septembre because my system language is French
```
* `-l, --lang`: specify which Wikipedia edition should be targeted
```sh
wd open -p -l sv Q123
# opens https://sv.wikipedia.org/wiki/September instead
```
Expand Down
3 changes: 2 additions & 1 deletion bin/wd-props
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ program
.arguments(strings.props.args)
.description(strings.props.description)
.option('-r, --reset', 'clear properties cache')
.option('-l, --lang <lang>', 'specify the properties labels language')
.parse(process.argv)

if (program.reset) return resetProperties()

var lang = program.args[0] || localLang || 'en'
const lang = program.lang || localLang || 'en'

const writeResultsToStdout = function (results) {
console.log(JSON.stringify(results, null, 2))
Expand Down
8 changes: 2 additions & 6 deletions bin/wd-wikiqid
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const strings = require('../lib/strings')
program
.arguments(strings.wikiqid.args)
.description(strings.wikiqid.description)
.option('-l, --lang <lang>', 'specify from which language the title comes')
.parse(process.argv)

const args = program.args
Expand All @@ -19,12 +20,7 @@ const _ = require('lodash')
const getRedirectedWikipediaTitle = require('../lib/get_redirected_wikipedia_title')

const last = args.slice(-1)[0]
var lang

if (last.length === 2) {
lang = args.pop()
}
lang = lang || localLang || 'en'
var lang = program.lang || localLang || 'en'

// allow to pass a title without having to put it in ""
var title = args.join(' ')
Expand Down
4 changes: 2 additions & 2 deletions lib/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ module.exports = {
description: "output the entity's data"
},
props: {
args: '[lang]',
args: '',
description: 'output the list of all Wikidata properties'
},
wikiqid: {
args: '<title> [lang]',
args: '<title>',
description: 'get a Wikidata id from a Wikipedia article title'
},
sparql: {
Expand Down

0 comments on commit d25724f

Please sign in to comment.