Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ class Glossary {
this._entries[term] = description
}

fromFile (filename) {
let rawdata = fs.readFileSync(filename)
let glossary = JSON.parse(rawdata)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're only supporting JSON, this could just a be a require instead.

for (var i in glossary) {
assert(i && i.length, `term is required for description ${glossary[i]}`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than re-doing this validation, we should just use the existing .add() method and get the existing validation for free.

assert(glossary[i] && glossary[i].length, `description of ${i} is required`)
assert(!(Object.keys(this.entries).includes(i)), `term ${i} has already been added`)
}
this._entries = glossary
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this._entries = glossary is not necessary. This line can be removed.

}

get entries () {
return this._entries
}
Expand Down
11 changes: 9 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# crowdin-glossary
# crowdin-glossary

Create and upload translation glossaries using the Crowdin API

Expand Down Expand Up @@ -51,6 +51,13 @@ call `glossary.upload()`
- `term` String (required)
- `description` String (required)

### `glossary.fromFile(filename)`

Uploads entries from the a file provided. Entries only exist in memory until you
call `glossary.upload()` but file remains unchanged.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"but file remains unchanged." doesn't seem necessary.


- `filename` String (required)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to mention that this should be a full path.


### `glossary.upload()`

Async function that uploads all the added terms to Crowdin.
Expand All @@ -67,7 +74,7 @@ A getter that returns the web URL of your project's glossary on crowdin.com

### `glossary.csv`

A getter that converts your entries into a valid CSV string for upload to
A getter that converts your entries into a valid CSV string for upload to
Crowdin. Used for internal purposes.

## License
Expand Down
Loading