-
Notifications
You must be signed in to change notification settings - Fork 2
feat: fromFile function add #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,17 @@ class Glossary { | |
| this._entries[term] = description | ||
| } | ||
|
|
||
| fromFile (filename) { | ||
| let rawdata = fs.readFileSync(filename) | ||
| let glossary = JSON.parse(rawdata) | ||
| for (var i in glossary) { | ||
| assert(i && i.length, `term is required for description ${glossary[i]}`) | ||
|
||
| 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| get entries () { | ||
| return this._entries | ||
| } | ||
|
|
||
| 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 | ||
|
|
||
|
|
@@ -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. | ||
|
||
|
|
||
| - `filename` String (required) | ||
|
||
|
|
||
| ### `glossary.upload()` | ||
|
|
||
| Async function that uploads all the added terms to Crowdin. | ||
|
|
@@ -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 | ||
|
|
||
There was a problem hiding this comment.
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
requireinstead.