Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Revert mjs conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
obulat committed Oct 14, 2021
1 parent 0bc0d4f commit 619894f
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 42 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"vue-i18n-extract": "vue-i18n-extract report -v './src/**/*.?(js|vue)' -l './src/locales/*.?(json)'",
"postinstall": "patch-package",
"prepare": "husky install",
"i18n:get-translations": "node src/locales/scripts/get-translations.mjs && node src/locales/scripts/get-validated-locales.mjs",
"i18n:generate-pot": "node src/locales/scripts/json-to-pot.mjs",
"i18n:update-locales": "node src/locales/scripts/update-locale-list.mjs"
"i18n:get-translations": "node src/locales/scripts/get-translations.js && node src/locales/scripts/get-validated-locales.js",
"i18n:generate-pot": "node src/locales/scripts/json-to-pot.js",
"i18n:update-locales": "node src/locales/scripts/update-locale-list.js"
},
"dependencies": {
"@nuxt/components": "^2.1.6",
Expand Down
2 changes: 1 addition & 1 deletion src/locales/po-files/openverse.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Openverse \n"
"Report-Msgid-Bugs-To: https://github.com/wordpress/openverse/issues \n"
"POT-Creation-Date: 2021-10-14T05:47:35+00:00\n"
"POT-Creation-Date: 2021-10-14T16:48:53+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
* Fetch the NGX-Translate JSON file for each supported language,
* convert to our JSON format, and save in the correct folder.
*/
import { writeFile } from 'fs/promises'
import os from 'os'
import axios from 'axios'
import ngxJsonToJson from './ngx-json-to-json.mjs'
import fs from 'fs-extra'

const localeFilename = process.cwd() + '/src/locales/scripts/locales-list.json'
const localeJSON = fs.readJsonSync(localeFilename)
const { writeFile } = require('fs/promises')
const os = require('os')
const axios = require('axios')
const ngxJsonToJson = require('./ngx-json-to-json')
const localeJSON = require('./locales-list.json')

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fs from 'fs-extra'
const localesListFile = process.cwd() + '/src/locales/scripts/locales-list.json'
const localesList = fs.readJsonSync(localesListFile)
const fs = require('fs')
const localesList = require('./locales-list.json')

const getValidatedLocales = () => {
return Object.values(localesList)
Expand All @@ -15,6 +14,8 @@ const getValidatedLocales = () => {
.filter((i) => fs.existsSync(process.cwd() + `/src/locales/${i.file}`))
}

console.log(process.cwd())

try {
let locales = getValidatedLocales()
const fileName = 'valid-locales.json'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const isEmptyObject = (a) => !Object.keys(a).length
const isSimple = (a) => !a || !isObject(a) || isEmptyObject(a)
const pop = (a) => a.pop() || []

export function getAllPaths(obj) {
function getAllPaths(obj) {
const result = []
const [currentResult, stack] = readPaths(obj)
result.push(...currentResult)
Expand Down Expand Up @@ -40,7 +40,7 @@ function readPaths(obj, path = '') {
}
return [result, stack]
}
export const getKeyValue = (key, value) => {
const getKeyValue = (key, value) => {
const selects = key.split('.')
selects.some((name, i) => {
const nestedName = selects.slice(i).join('.')
Expand All @@ -59,3 +59,4 @@ export const getKeyValue = (key, value) => {

return value
}
module.exports = { getAllPaths, getKeyValue }
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
msgid untranslated-string
msgstr translated-string
*/
import { getAllPaths, getKeyValue } from './json-helpers.mjs'
import { getParsedVueFiles } from './parse-vue-files.mjs'
import fs from 'fs-extra'
const { getAllPaths, getKeyValue } = require('./json-helpers')
const { getParsedVueFiles } = require('./parse-vue-files')
const json = require('../en.json')
const fs = require('fs-extra')

const curlyRegex = new RegExp('{[a-zA-Z-]*}')
const containsCurlyWord = (string) => curlyRegex.test(string)
Expand All @@ -27,7 +28,7 @@ const checkStringForVars = (string) =>
* @param string
* @return {string}
*/
export const replaceVarsPlaceholders = (string) => {
const replaceVarsPlaceholders = (string) => {
if (!containsCurlyWord(string)) {
return string
}
Expand Down Expand Up @@ -95,7 +96,7 @@ msgstr ""
// msgid untranslated-string
// msgstr translated-string

export function potTime(json) {
function potTime(json) {
let potFileString = ''
const jsonKeys = getAllPaths(json)
jsonKeys.forEach((key) => {
Expand Down Expand Up @@ -129,8 +130,8 @@ msgstr[1] ""`
return potFileString
}

const enFileName = process.cwd() + '/src/locales/en.json'
const json = fs.readJsonSync(enFileName)
// const enFileName = process.cwd() + '/src/locales/en.json'
// const json = fs.readJsonSync(enFileName)

const potFile = `${POT_FILE_META}${potTime(json)}\n`
try {
Expand All @@ -140,3 +141,4 @@ try {
} catch (err) {
console.error(err)
}
module.exports = { replaceVarsPlaceholders, potTime }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import set from 'lodash/set.js'
const set = require('lodash/set')

/**
* Convert an NGX-Translate object to a nested JSON object
Expand Down Expand Up @@ -44,4 +44,4 @@ function ngxJsonToJson(ngxObject) {
// )
// )

export default ngxJsonToJson
module.exports = ngxJsonToJson
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// This implementation is loosely copied from vue-i18n-extract
// https://github.com/pixari/vue-i18n-extract
import fs from 'fs'
import path, { dirname } from 'path'
import glob from 'glob'
import { fileURLToPath } from 'url'

const __filename = fileURLToPath(import.meta.url)
const fs = require('fs')
const path = require('path')
const glob = require('glob')

const BASE_PATH = dirname(dirname(dirname(__filename)))
const BASE_PATH = path.dirname(path.dirname(__dirname))

function readVueFiles(src) {
const targetFiles = glob.sync(src)
Expand Down Expand Up @@ -115,7 +113,9 @@ function parseVueFiles(vueFilesPath) {
* from the BASE_PATH (`openverse-frontend/src`)
* @return {Array<Object>}
*/
export const getParsedVueFiles = (vueFiles) => {
const getParsedVueFiles = (vueFiles) => {
const resolvedVueFiles = path.resolve(BASE_PATH, vueFiles)
return parseVueFiles(resolvedVueFiles)
}

module.exports = { getParsedVueFiles }
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// locales.py
// This script extracts data for locales available in GlotPress, and
// saves it to `locales-list.json`
import axios from 'axios'
import fs from 'fs'

const axios = require('axios')
const fs = require('fs')

const base_url =
'https://raw.githubusercontent.com/GlotPress/GlotPress-WP/develop/locales/locales.php'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
potTime,
replaceVarsPlaceholders,
} from '~/locales/scripts/json-to-pot.mjs'

import clonedeep from 'lodash.clonedeep'
import { getKeyValue } from '~/locales/scripts/json-helpers.mjs'
import { replaceVarsPlaceholders } from '~/locales/scripts/json-to-pot.js'

describe('replaceVarsPlaceholders', () => {
it('replaces lower case placeholders', () => {
Expand Down

0 comments on commit 619894f

Please sign in to comment.