-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add citation styles as git submodule (#4431)
* add citation styles as git submodule * add CSL locales as git submodule
- Loading branch information
1 parent
f8b1e2d
commit 11a62dd
Showing
7 changed files
with
80 additions
and
39 deletions.
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,6 @@ | ||
[submodule "src/main/resources/csl-styles"] | ||
path = src/main/resources/csl-styles | ||
url = https://github.com/citation-style-language/styles.git | ||
[submodule "src/main/resources/csl-locales"] | ||
path = src/main/resources/csl-locales | ||
url = https://github.com/citation-style-language/locales.git |
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
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
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
38 changes: 38 additions & 0 deletions
38
src/main/java/org/jabref/logic/citationstyle/JabRefLocaleProvider.java
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,38 @@ | ||
package org.jabref.logic.citationstyle; | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.net.URL; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import de.undercouch.citeproc.LocaleProvider; | ||
import de.undercouch.citeproc.helper.CSLUtils; | ||
|
||
/** | ||
* A {@link LocaleProvider} that loads locales from a directory in the current module. | ||
* | ||
* This implementation is only a slight adaption of {@link de.undercouch.citeproc.DefaultLocaleProvider}. | ||
*/ | ||
public class JabRefLocaleProvider implements LocaleProvider { | ||
|
||
private static final String LOCALES_ROOT = "/csl-locales"; | ||
|
||
private final Map<String, String> locales = new HashMap<>(); | ||
|
||
@Override | ||
public String retrieveLocale(String lang) { | ||
return locales.computeIfAbsent(lang, locale -> { | ||
try { | ||
URL url = getClass().getResource(LOCALES_ROOT + "/locales-" + locale + ".xml"); | ||
if (url == null) { | ||
throw new IllegalArgumentException("Unable to load locale " + locale); | ||
} | ||
|
||
return CSLUtils.readURLToString(url, "UTF-8"); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException("failed to read locale " + locale, e); | ||
} | ||
}); | ||
} | ||
} |
Submodule csl-locales
added at
29ed2f
Submodule csl-styles
added at
6ed87f