mirror of
https://github.com/mudita/mudita-center.git
synced 2026-08-07 05:23:27 -04:00
Added common config for phrase API requests
This commit is contained in:
1 parent
bbe230124f
commit
f198025578
3 files changed
+29
-26
No files matched your search
@@ -1,6 +1,7 @@
|
||||
const axios = require("axios")
|
||||
const fs = require("fs-extra")
|
||||
require("dotenv").config()
|
||||
const { localesUrl, axiosConfig } = require("../src/common/configs/phrase")
|
||||
|
||||
/**
|
||||
* Function that updates default translations files. It fetches all translations
|
||||
@@ -19,27 +20,15 @@ require("dotenv").config()
|
||||
defaultLanguage: "",
|
||||
}
|
||||
|
||||
const { data: locales } = await axios.get(
|
||||
`${process.env.PHRASE_API_URL}/locales/`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `token ${process.env.PHRASE_API_KEY}`,
|
||||
},
|
||||
}
|
||||
)
|
||||
const { data: locales } = await axios.get(localesUrl, axiosConfig)
|
||||
|
||||
await fs.ensureDir("./src/renderer/locales/default/")
|
||||
|
||||
for (const { id, code, default: defaultLanguage } of locales) {
|
||||
const { data } = await axios.get(
|
||||
`${process.env.PHRASE_API_URL}/locales/${id}/download`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `token ${process.env.PHRASE_API_KEY}`,
|
||||
},
|
||||
params: { file_format: "react_simple_json" },
|
||||
}
|
||||
)
|
||||
const { data } = await axios.get(`${localesUrl}/${id}/download`, {
|
||||
...axiosConfig,
|
||||
params: { file_format: "react_simple_json" },
|
||||
})
|
||||
|
||||
if (defaultLanguage) {
|
||||
config.defaultLanguage = code
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
require("dotenv").config()
|
||||
|
||||
const localesUrl = `${process.env.PHRASE_API_URL}/locales`
|
||||
|
||||
const axiosConfig = {
|
||||
headers: {
|
||||
Authorization: `token ${process.env.PHRASE_API_KEY}`,
|
||||
},
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
localesUrl,
|
||||
axiosConfig,
|
||||
}
|
||||
@@ -2,10 +2,13 @@ import settingsStore from "App/main/store/settings"
|
||||
import axios from "axios"
|
||||
import translationStores from "App/main/store/translations"
|
||||
import { availableLanguages } from "App/translations.config.json"
|
||||
import { axiosConfig, localesUrl } from "App/common/configs/phrase"
|
||||
|
||||
const updateTranslations = async () => {
|
||||
const language = settingsStore.get("language") as string
|
||||
const id = availableLanguages.find(({ code }) => code === language)?.id
|
||||
// TODO: Replace with the new logger
|
||||
console.log(`Preparing translation update for language "${language}"`)
|
||||
|
||||
try {
|
||||
if (!id) {
|
||||
@@ -15,17 +18,14 @@ const updateTranslations = async () => {
|
||||
)
|
||||
)
|
||||
}
|
||||
const { data } = await axios.get(
|
||||
`${process.env.PHRASE_API_URL}/locales/${id || "en"}/download`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `token ${process.env.PHRASE_API_KEY}`,
|
||||
},
|
||||
params: { file_format: "react_simple_json" },
|
||||
}
|
||||
)
|
||||
const { data } = await axios.get(`${localesUrl}/${id}/download`, {
|
||||
...axiosConfig,
|
||||
params: { file_format: "react_simple_json" },
|
||||
})
|
||||
|
||||
translationStores[language].store = data
|
||||
// TODO: Replace with the new logger
|
||||
console.log(`Translation for language "${language}" applied successfully`)
|
||||
} catch (error) {
|
||||
// TODO: Replace with the new logger
|
||||
console.log(error)
|
||||
|
||||
Reference in new issue
Block a user