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
Add /Lang Setting plugin #1456
Merged
Merged
Add /Lang Setting plugin #1456
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6a1b09c
Add files via upload
Uzlopak 9126524
add tests
Uzlopak c74f433
Update saucelabs.karma.conf.js
Uzlopak fdaa3b9
Merge branch 'master' into add_lang_plugin
Uzlopak e0a71ee
fix possible merging error
Uzlopak 101645d
Merge branch 'master' into add_lang_plugin
MrRio 619795b
Merge branch 'master' into add_lang_plugin
MrRio d0f4df8
fix minor bug
Uzlopak 966dad7
hopefull removed all dupes
Uzlopak 6897f2f
Update main.js
Uzlopak File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,243 @@ | ||
/** | ||
* jsPDF setLanguage Plugin | ||
* | ||
* Licensed under the MIT License. | ||
* http://opensource.org/licenses/mit-license | ||
*/ | ||
|
||
(function (jsPDFAPI) { | ||
"use strict"; | ||
|
||
/** | ||
* Add Language Tag to PDF | ||
* | ||
* @returns {jsPDF} | ||
* @name setLanguage | ||
* @example | ||
* var doc = new jsPDF() | ||
* doc.text(10, 10, 'This is a test') | ||
* doc.setLanguage("en-US") | ||
* doc.save('english.pdf') | ||
*/ | ||
jsPDFAPI.setLanguage = function (langCode) { | ||
"use strict"; | ||
|
||
var langCodes = { | ||
"af": "Afrikaans", | ||
"sq": "Albanian", | ||
"ar": "Arabic (Standard)", | ||
"ar-DZ": "Arabic (Algeria)", | ||
"ar-BH": "Arabic (Bahrain)", | ||
"ar-EG": "Arabic (Egypt)", | ||
"ar-IQ": "Arabic (Iraq)", | ||
"ar-JO": "Arabic (Jordan)", | ||
"ar-KW": "Arabic (Kuwait)", | ||
"ar-LB": "Arabic (Lebanon)", | ||
"ar-LY": "Arabic (Libya)", | ||
"ar-MA": "Arabic (Morocco)", | ||
"ar-OM": "Arabic (Oman)", | ||
"ar-QA": "Arabic (Qatar)", | ||
"ar-SA": "Arabic (Saudi Arabia)", | ||
"ar-SY": "Arabic (Syria)", | ||
"ar-TN": "Arabic (Tunisia)", | ||
"ar-AE": "Arabic (U.A.E.)", | ||
"ar-YE": "Arabic (Yemen)", | ||
"ar": "Aragonese", | ||
"hy": "Armenian", | ||
"as": "Assamese", | ||
"ast": "Asturian", | ||
"az": "Azerbaijani", | ||
"eu": "Basque", | ||
"bg": "Bulgarian", | ||
"be": "Belarusian", | ||
"bn": "Bengali", | ||
"bs": "Bosnian", | ||
"br": "Breton", | ||
"bg": "Bulgarian", | ||
"my": "Burmese", | ||
"ca": "Catalan", | ||
"ch": "Chamorro", | ||
"ce": "Chechen", | ||
"zh": "Chinese", | ||
"zh-HK": "Chinese (Hong Kong)", | ||
"zh-CN": "Chinese (PRC)", | ||
"zh-SG": "Chinese (Singapore)", | ||
"zh-TW": "Chinese (Taiwan)", | ||
"cv": "Chuvash", | ||
"co": "Corsican", | ||
"cr": "Cree", | ||
"hr": "Croatian", | ||
"cs": "Czech", | ||
"da": "Danish", | ||
"nl": "Dutch (Standard)", | ||
"nl-BE": "Dutch (Belgian)", | ||
"en": "English", | ||
"en-AU": "English (Australia)", | ||
"en-BZ": "English (Belize)", | ||
"en-CA": "English (Canada)", | ||
"en-IE": "English (Ireland)", | ||
"en-JM": "English (Jamaica)", | ||
"en-NZ": "English (New Zealand)", | ||
"en-PH": "English (Philippines)", | ||
"en-ZA": "English (South Africa)", | ||
"en-TT": "English (Trinidad & Tobago)", | ||
"en-GB": "English (United Kingdom)", | ||
"en-US": "English (United States)", | ||
"en-ZW": "English (Zimbabwe)", | ||
"eo": "Esperanto", | ||
"et": "Estonian", | ||
"fo": "Faeroese", | ||
"fa": "Farsi", | ||
"fj": "Fijian", | ||
"fi": "Finnish", | ||
"fr": "French (Standard)", | ||
"fr-BE": "French (Belgium)", | ||
"fr-CA": "French (Canada)", | ||
"fr-FR": "French (France)", | ||
"fr-LU": "French (Luxembourg)", | ||
"fr-MC": "French (Monaco)", | ||
"fr-CH": "French (Switzerland)", | ||
"fy": "Frisian", | ||
"fur": "Friulian", | ||
"gd": "Gaelic (Scots)", | ||
"gd-IE": "Gaelic (Irish)", | ||
"gl": "Galacian", | ||
"ka": "Georgian", | ||
"de": "German (Standard)", | ||
"de-AT": "German (Austria)", | ||
"de-DE": "German (Germany)", | ||
"de-LI": "German (Liechtenstein)", | ||
"de-LU": "German (Luxembourg)", | ||
"de-CH": "German (Switzerland)", | ||
"el": "Greek", | ||
"gu": "Gujurati", | ||
"ht": "Haitian", | ||
"he": "Hebrew", | ||
"hi": "Hindi", | ||
"hu": "Hungarian", | ||
"is": "Icelandic", | ||
"id": "Indonesian", | ||
"iu": "Inuktitut", | ||
"ga": "Irish", | ||
"it": "Italian (Standard)", | ||
"it-CH": "Italian (Switzerland)", | ||
"ja": "Japanese", | ||
"kn": "Kannada", | ||
"ks": "Kashmiri", | ||
"kk": "Kazakh", | ||
"km": "Khmer", | ||
"ky": "Kirghiz", | ||
"tlh": "Klingon", | ||
"ko": "Korean", | ||
"ko-KP": "Korean (North Korea)", | ||
"ko-KR": "Korean (South Korea)", | ||
"la": "Latin", | ||
"lv": "Latvian", | ||
"lt": "Lithuanian", | ||
"lb": "Luxembourgish", | ||
"mk": "FYRO Macedonian", | ||
"ms": "Malay", | ||
"ml": "Malayalam", | ||
"mt": "Maltese", | ||
"mi": "Maori", | ||
"mr": "Marathi", | ||
"mo": "Moldavian", | ||
"nv": "Navajo", | ||
"ng": "Ndonga", | ||
"ne": "Nepali", | ||
"no": "Norwegian", | ||
"nb": "Norwegian (Bokmal)", | ||
"nn": "Norwegian (Nynorsk)", | ||
"oc": "Occitan", | ||
"or": "Oriya", | ||
"om": "Oromo", | ||
"fa": "Persian", | ||
"fa-IR": "Persian/Iran", | ||
"pl": "Polish", | ||
"pt": "Portuguese", | ||
"pt-BR": "Portuguese (Brazil)", | ||
"pa": "Punjabi", | ||
"pa-IN": "Punjabi (India)", | ||
"pa-PK": "Punjabi (Pakistan)", | ||
"qu": "Quechua", | ||
"rm": "Rhaeto-Romanic", | ||
"ro": "Romanian", | ||
"ro-MO": "Romanian (Moldavia)", | ||
"ru": "Russian", | ||
"ru-MO": "Russian (Moldavia)", | ||
"sz": "Sami (Lappish)", | ||
"sg": "Sango", | ||
"sa": "Sanskrit", | ||
"sc": "Sardinian", | ||
"gd": "Scots Gaelic", | ||
"sd": "Sindhi", | ||
"si": "Singhalese", | ||
"sr": "Serbian", | ||
"sk": "Slovak", | ||
"sl": "Slovenian", | ||
"so": "Somani", | ||
"sb": "Sorbian", | ||
"es": "Spanish", | ||
"es-AR": "Spanish (Argentina)", | ||
"es-BO": "Spanish (Bolivia)", | ||
"es-CL": "Spanish (Chile)", | ||
"es-CO": "Spanish (Colombia)", | ||
"es-CR": "Spanish (Costa Rica)", | ||
"es-DO": "Spanish (Dominican Republic)", | ||
"es-EC": "Spanish (Ecuador)", | ||
"es-SV": "Spanish (El Salvador)", | ||
"es-GT": "Spanish (Guatemala)", | ||
"es-HN": "Spanish (Honduras)", | ||
"es-MX": "Spanish (Mexico)", | ||
"es-NI": "Spanish (Nicaragua)", | ||
"es-PA": "Spanish (Panama)", | ||
"es-PY": "Spanish (Paraguay)", | ||
"es-PE": "Spanish (Peru)", | ||
"es-PR": "Spanish (Puerto Rico)", | ||
"es-ES": "Spanish (Spain)", | ||
"es-UY": "Spanish (Uruguay)", | ||
"es-VE": "Spanish (Venezuela)", | ||
"sx": "Sutu", | ||
"sw": "Swahili", | ||
"sv": "Swedish", | ||
"sv-FI": "Swedish (Finland)", | ||
"sv-SV": "Swedish (Sweden)", | ||
"ta": "Tamil", | ||
"tt": "Tatar", | ||
"te": "Teluga", | ||
"th": "Thai", | ||
"tig": "Tigre", | ||
"ts": "Tsonga", | ||
"tn": "Tswana", | ||
"tr": "Turkish", | ||
"tk": "Turkmen", | ||
"uk": "Ukrainian", | ||
"hsb": "Upper Sorbian", | ||
"ur": "Urdu", | ||
"ve": "Venda", | ||
"vi": "Vietnamese", | ||
"vo": "Volapuk", | ||
"wa": "Walloon", | ||
"cy": "Welsh", | ||
"xh": "Xhosa", | ||
"ji": "Yiddish", | ||
"zu": "Zulu", | ||
}; | ||
|
||
if (this.internal.languageSettings === undefined) { | ||
this.internal.languageSettings = {}; | ||
this.internal.languageSettings.isSubscribed = false; | ||
} | ||
|
||
if (langCodes[langCode] !== undefined) { | ||
this.internal.languageSettings.languageCode = langCode; | ||
if (this.internal.languageSettings.isSubscribed === false) { | ||
this.internal.events.subscribe("putCatalog", function () { | ||
this.internal.write("/Lang (" + this.internal.languageSettings.languageCode + ")"); | ||
}); | ||
this.internal.languageSettings.isSubscribed = true; | ||
} | ||
} | ||
return this; | ||
}; | ||
})(jsPDF.API); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict' | ||
/* global describe, it, jsPDF, comparePdf, expect */ | ||
/** | ||
* Standard spec tests | ||
*/ | ||
|
||
describe('Plugin: setlanguage', () => { | ||
it('set english (US)', () => { | ||
const doc = new jsPDF(); | ||
doc.setLanguage("en-US"); | ||
|
||
comparePdf(doc.output(), 'enUS.pdf', 'setlanguage'); | ||
}); | ||
|
||
it('refuse non-existing-language', () => { | ||
const doc = new jsPDF(); | ||
doc.setLanguage("zz"); | ||
|
||
comparePdf(doc.output(), 'blank.pdf', 'text') | ||
}); | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
aragonese = an and not ar