Skip to content

Commit

Permalink
Move to crowdin enterprise (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Kleinekathöfer authored Jan 27, 2022
1 parent ace30ef commit 1c1f92b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,5 @@ jobs:
GITHUB_TOKEN=${{ github.token }}
CROWDIN_TOKEN=${{ secrets.CROWDIN_TOKEN }}
CROWDIN_PROJECT_ID=${{ secrets.CROWDIN_PROJECT_ID }}
CROWDIN_BASE_URL=https://spongepowered.crowdin.com
BASE_URL=https://docs.spongepowered.org
7 changes: 4 additions & 3 deletions src/homepage/data/crowdin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const github = require('./github');

const crowdinProjectId = process.env.CROWDIN_PROJECT_ID;
const crowdinToken = process.env.CROWDIN_TOKEN;
const crowdinBaseUrl = process.env.CROWDIN_BASE_URL || "https://crowdin.com";

const localLanguages = require('./languages');

Expand All @@ -13,7 +14,7 @@ const headers = {

module.exports.getLocaleMappings = () =>
rp({
uri: 'https://api.crowdin.com/api/v2/languages?limit=500',
uri: `${crowdinBaseUrl}/api/v2/languages?limit=500`,
headers: {
'Accept': 'application/json'
},
Expand All @@ -34,7 +35,7 @@ if (crowdinProjectId && crowdinToken) {
getBranchMappings = () => new Promise((resolve, reject) => {
let crowdinBranches = {};
rp({
uri: `https://api.crowdin.com/api/v2/projects/${crowdinProjectId}/branches`,
uri: `${crowdinBaseUrl}/api/v2/projects/${crowdinProjectId}/branches`,
headers: headers,
json: true
}).then((resp) => {
Expand All @@ -53,7 +54,7 @@ if (crowdinProjectId && crowdinToken) {

result[0].forEach(version => {
promises.push(rp({
uri: `https://api.crowdin.com/api/v2/projects/${crowdinProjectId}/branches/${result[1][version]}/languages/progress?limit=500`,
uri: `${crowdinBaseUrl}/api/v2/projects/${crowdinProjectId}/branches/${result[1][version]}/languages/progress?limit=500`,
headers: headers,
json: true
}).then(resp => {
Expand Down
2 changes: 1 addition & 1 deletion src/theme/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = (0, 6, 3)
VERSION = (1, 0, 0)
__version__ = '.'.join(str(v) for v in VERSION)


Expand Down
4 changes: 2 additions & 2 deletions src/theme/languages.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import json
import os.path

import babel
import requests
from sphinx.util import logging

from . import __version__

CROWDIN_BASE_URL = os.getenv('CROWDIN_BASE_URL', 'https://crowdin.com')
LOCAL_LANGUAGES_FILE = os.path.join(os.path.dirname(__file__), 'languages.json')
LANGUAGES_FILE = 'build/languages.json'
languages = None
Expand Down Expand Up @@ -50,7 +50,7 @@ def load_languages():
languages = json.load(f)
else:
# Load Crowdin languages from API
r = requests.get('https://api.crowdin.com/api/v2/languages?limit=500')
r = requests.get('%s/api/v2/languages?limit=500' % CROWDIN_BASE_URL)
r.raise_for_status()

languages = {lang['data']['locale'].replace('-', '_'): {
Expand Down
9 changes: 5 additions & 4 deletions src/theme/scripts/list-translations
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import sys

CROWDIN_PROJECT_ID = os.environ['CROWDIN_PROJECT_ID']
CROWDIN_TOKEN = os.environ['CROWDIN_TOKEN']
CROWDIN_BASE_URL = os.environ['CROWDIN_BASE_URL']

BRANCH = sys.argv[1]

Expand All @@ -15,23 +16,23 @@ headers = {
}

# Load language mappings
r = requests.get('https://api.crowdin.com/api/v2/languages?limit=500')
r = requests.get('%s/api/v2/languages?limit=500' % CROWDIN_BASE_URL)
r.raise_for_status()

# Map Crowdin codes to locale codes
languages = {lang['data']['id']: lang['data']['locale'].replace('-', '_') for lang in r.json()['data']}

branchId = None
r = requests.get('https://api.crowdin.com/api/v2/projects/%s/branches' % CROWDIN_PROJECT_ID, headers=headers)
r = requests.get('%s/api/v2/projects/%s/branches' % (CROWDIN_BASE_URL, CROWDIN_PROJECT_ID), headers=headers)
r.raise_for_status()
for language in r.json()['data']:
if language['data']['name'] == BRANCH:
branchId = language['data']['id']
if not branchId:
sys.exit(f"Could not find specified branch: ${branchId}!")

r = requests.get('https://api.crowdin.com/api/v2/projects/%s/branches/%s/languages/progress?limit=500' %
(CROWDIN_PROJECT_ID, branchId), headers=headers)
r = requests.get('%s/api/v2/projects/%s/branches/%s/languages/progress?limit=500' %
(CROWDIN_BASE_URL, CROWDIN_PROJECT_ID, branchId), headers=headers)
r.raise_for_status()

locales = []
Expand Down
9 changes: 5 additions & 4 deletions src/theme/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
{% block extrahead %}
{% if language == 'translate' %}
{# Include Crowdin In-Context Localization JS app if this is the translation build #}
<script>
// Set Crowdin project context for In-Context Localization
var _jipt = [['project', 'sponge-docs']];
<script type="text/javascript">
var _jipt = [];
_jipt.push(['project', '0a86ffd1f9737b034a2ff35f6611ae96']);
_jipt.push(['domain', 'spongepowered']);
</script>
<script src="https://cdn.crowdin.com/jipt/jipt.js"></script>
<script type="text/javascript" src="https://cdn.crowdin.com/jipt/jipt.js"></script>
{% endif %}
{% endblock %}

0 comments on commit 1c1f92b

Please sign in to comment.