Skip to content

Instantly share code, notes, and snippets.

@sagartalla
Last active August 29, 2019 08:05
Show Gist options
  • Save sagartalla/d6f56f29c7b55d1ebf9cd2c16e9f8f45 to your computer and use it in GitHub Desktop.
Save sagartalla/d6f56f29c7b55d1ebf9cd2c16e9f8f45 to your computer and use it in GitHub Desktop.
import "./styles.css";
import axios from "axios";
import _ from "lodash";
import EN_KEYWORDS from "./en";
import AR_KEYWORDS from "./ar";
axios
.get(
"https://spreadsheets.google.com/feeds/list/157erdICVrm0UhD37trQDZuzS7JG4T5ejwoZS9zUilzo/od6/public/values?alt=json"
)
.then(({ data }) => {
let transData = data.feed.entry.map(element => {
var acc = [];
_.forEach(element, (value, key) => {
if (/^gsx\$.+/.test(key)) {
acc.push(value.$t);
}
});
return [acc[1], acc[2]];
});
transData.shift();
transData = transData.reduce((acc, value, index) => {
acc[value[0].toLowerCase()] = value[1];
return acc;
}, {});
const arKeywords = {};
_.map(EN_KEYWORDS, (page, pageKey) => {
_.map(page, (item, itemKey) => {
arKeywords[pageKey] = arKeywords[pageKey] || {};
arKeywords[pageKey][itemKey] =
transData[item.toLowerCase()] ||
(AR_KEYWORDS[pageKey]
? AR_KEYWORDS[pageKey][itemKey]
: EN_KEYWORDS[pageKey]
? EN_KEYWORDS[pageKey][itemKey]
: "");
delete transData[item.toLowerCase()];
});
});
console.log(JSON.stringify(transData));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment