Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
dev:translators:coding [2018/12/26 06:49]
dstillman Add proxy: false attachment flag
dev:translators:coding [2020/04/22 18:15] (current)
dstillman [detectWeb]
Line 3: Line 3:
 Below we will describe how the ''​detect*''​ and ''​do*''​ functions of Zotero [[dev/​translators]] can and should be coded. If you are unfamiliar with JavaScript, make sure to check out a [[https://​developer.mozilla.org/​en/​JavaScript/​A_re-introduction_to_JavaScript|JavaScript tutorial]] to get familiar with the syntax. In addition to the information on this page, it can often be very informative to look at existing translators to see how things are done. A [[https://​www.mediawiki.org/​wiki/​Citoid/​Creating_Zotero_translators|particularly helpful guide]] with up-to-date recommendation on best coding practices is provided by the wikimedia foundation, whose tool Citoid uses Zotero translators. Below we will describe how the ''​detect*''​ and ''​do*''​ functions of Zotero [[dev/​translators]] can and should be coded. If you are unfamiliar with JavaScript, make sure to check out a [[https://​developer.mozilla.org/​en/​JavaScript/​A_re-introduction_to_JavaScript|JavaScript tutorial]] to get familiar with the syntax. In addition to the information on this page, it can often be very informative to look at existing translators to see how things are done. A [[https://​www.mediawiki.org/​wiki/​Citoid/​Creating_Zotero_translators|particularly helpful guide]] with up-to-date recommendation on best coding practices is provided by the wikimedia foundation, whose tool Citoid uses Zotero translators.
  
-While translators can be written with any text editor, the Zotero add-on [[dev/​translators/​scaffold|Scaffold]] can make writing them much easier, as it provides the option to test and troubleshoot translators relatively quickly.+While translators can be written with any text editor, the built-in [[dev/​translators/​scaffold|Translator Editor]] can make writing them much easier, as it provides the option to test and troubleshoot translators relatively quickly.
  
  
Line 15: Line 15:
  
 <code javascript>​function detectWeb(doc,​ url) { <code javascript>​function detectWeb(doc,​ url) {
-  
  if (url.indexOf("​search/​results"​) != -1) {  if (url.indexOf("​search/​results"​) != -1) {
  return "​multiple";​  return "​multiple";​
- } else if (url.indexOf("​content/​article"​) != -1) {+ } 
 + else if (url.indexOf("​content/​article"​) != -1) {
  return "​journalArticle";​  return "​journalArticle";​
  }  }
 + return false;
 }</​code>​ }</​code>​
  
Line 238: Line 239:
 ===== Utility Functions ===== ===== Utility Functions =====
  
-Zotero provides several [[https://​github.com/​zotero/​zotero/​blob/​4.0/​chrome/​content/​zotero/​xpcom/​utilities.js|utility functions]] for translators to use. Some of them are used for asynchronous and synchronous HTTP requests; those are [[#​batch_saving|discussed above]]. In addition to those HTTP functions and the many standard functions provided by JavaScript, Zotero provides:+Zotero provides several [[https://​github.com/​zotero/​zotero/​blob/​master/​chrome/​content/​zotero/​xpcom/​utilities.js|utility functions]] for translators to use. Some of them are used for asynchronous and synchronous HTTP requests; those are [[#​batch_saving|discussed above]]. In addition to those HTTP functions and the many standard functions provided by JavaScript, Zotero provides:
   * ''​Zotero.Utilities.capitalizeTitle(title,​ ignorePreference)''​\\ Applies English-style title case to the string, if the capitalizeTitles [[/​support/​hidden_prefs|hidden preference]] is set. If ''​ignorePreference''​ is true, title case will be applied even if the preference is set to false. This function is often useful for fixing capitalization of personal names, in conjunction with the built-in string method ''​text.toLowerCase()''​.   * ''​Zotero.Utilities.capitalizeTitle(title,​ ignorePreference)''​\\ Applies English-style title case to the string, if the capitalizeTitles [[/​support/​hidden_prefs|hidden preference]] is set. If ''​ignorePreference''​ is true, title case will be applied even if the preference is set to false. This function is often useful for fixing capitalization of personal names, in conjunction with the built-in string method ''​text.toLowerCase()''​.
   * ''​Zotero.Utilities.cleanAuthor(author,​ creatorType,​ hasComma)''​\\ Attempts to split the given string into firstName and lastName components, splitting on a comma if desired and performs some clean-up (e.g. removes unnecessary white-spaces and punctuation). The creatorType (see the [[http://​gimranov.com/​research/​zotero/​creator-types|list of valid creator types]] for each item type) will be just passed trough. Returns a creator object of the form: ''​{ lastName: , firstName: , creatorType:​ }'',​ which can for example used directly in ''​item.creators.push()''​ as argument.   * ''​Zotero.Utilities.cleanAuthor(author,​ creatorType,​ hasComma)''​\\ Attempts to split the given string into firstName and lastName components, splitting on a comma if desired and performs some clean-up (e.g. removes unnecessary white-spaces and punctuation). The creatorType (see the [[http://​gimranov.com/​research/​zotero/​creator-types|list of valid creator types]] for each item type) will be just passed trough. Returns a creator object of the form: ''​{ lastName: , firstName: , creatorType:​ }'',​ which can for example used directly in ''​item.creators.push()''​ as argument.
dev/translators/coding.1545824969.txt.gz · Last modified: 2018/12/26 06:49 by dstillman