Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use lang with api queries #118

Merged
merged 9 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"test": "react-scripts test --env=jsdom",
"prettier": "prettier --write \"src/**/*.{js,jsx,ts,tsx,json,css,scss,md}\"",
"eject": "react-scripts eject",
"prebuild": "node scripts/get-version.js && node scripts/get-ammo-data.js && node scripts/get-traders.js && node scripts/get-quests.js && node scripts/update-props.js && node scripts/get-contributors.js && node scripts/build-sitemap.js && node scripts/build-guides.js",
"prebuild": "node scripts/get-version.js && node scripts/get-ammo-data.js && node scripts/get-traders.js && node scripts/get-quests.js && node scripts/update-props.js && node scripts/get-contributors.js && node scripts/build-sitemap.js && node scripts/build-guides.js && node scripts/translate-trader-icons.js",
"postbuild": "node scripts/build-redirects.js",
"stage": "npx rimraf build && npm run build && npm run preview",
"preview": "npx serve build -l 3001 -s",
Expand Down
Binary file added public/images/барахольщик-icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/егерь-icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/лыжник-icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/механик-icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/миротворец-icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/прапор-icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/скупщик-icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/терапевт-icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions scripts/translate-trader-icons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const { readdirSync, readFileSync, copyFile } = require('fs');

const dir = 'src/translations';

// Loop through all folders in the src/translations directory
const items = readdirSync(dir);
console.log(items);

// Loop through each folder in the src/translations directory
for (const item of items) {
let rawdata = readFileSync(`${dir}/${item}/translation.json`);
let translationsParsed = JSON.parse(rawdata);
const prapor = translationsParsed.Prapor.toLowerCase();
const skier = translationsParsed.Skier.toLowerCase();
const peacekeeper = translationsParsed.Peacekeeper.toLowerCase();
const therapist = translationsParsed.Therapist.toLowerCase();
const mechanic = translationsParsed.Mechanic.toLowerCase();
const ragman = translationsParsed.Ragman.toLowerCase();
const fence = translationsParsed.Fence.toLowerCase();
const jaeger = translationsParsed.Jaeger.toLowerCase();

copyFile('public/images/prapor-icon.jpg', `public/images/${prapor}-icon.jpg`, (err) => {
if (err)
throw err;
console.log(`prapor-icon.jpg was copied to ${prapor}-icon.jpg`);
});

copyFile('public/images/skier-icon.jpg', `public/images/${skier}-icon.jpg`, (err) => {
if (err)
throw err;
console.log(`skier-icon.jpg was copied to ${skier}-icon.jpg`);
});

copyFile('public/images/peacekeeper-icon.jpg', `public/images/${peacekeeper}-icon.jpg`, (err) => {
if (err)
throw err;
console.log(`peacekeeper-icon.jpg was copied to ${peacekeeper}-icon.jpg`);
});

copyFile('public/images/therapist-icon.jpg', `public/images/${therapist}-icon.jpg`, (err) => {
if (err)
throw err;
console.log(`therapist-icon.jpg was copied to ${therapist}-icon.jpg`);
});

copyFile('public/images/mechanic-icon.jpg', `public/images/${mechanic}-icon.jpg`, (err) => {
if (err)
throw err;
console.log(`mechanic-icon.jpg was copied to ${mechanic}-icon.jpg`);
});

copyFile('public/images/ragman-icon.jpg', `public/images/${ragman}-icon.jpg`, (err) => {
if (err)
throw err;
console.log(`ragman-icon.jpg was copied to ${ragman}-icon.jpg`);
});

copyFile('public/images/fence-icon.jpg', `public/images/${fence}-icon.jpg`, (err) => {
if (err)
throw err;
console.log(`fence-icon.jpg was copied to ${fence}-icon.jpg`);
});

copyFile('public/images/jaeger-icon.jpg', `public/images/${jaeger}-icon.jpg`, (err) => {
if (err)
throw err;
console.log(`jaeger-icon.jpg was copied to ${jaeger}-icon.jpg`);
});
}
118 changes: 62 additions & 56 deletions src/features/items/do-fetch-items.js
Original file line number Diff line number Diff line change
@@ -1,71 +1,77 @@
import calculateFee from '../../modules/flea-market-fee';
import camelcaseToDashes from '../../modules/camelcase-to-dashes';
import { langCode } from '../../modules/lang-helpers';

const NOTES = {
'60a2828e8689911a226117f9': `Can't store Pillbox, Day Pack, LK 3F or MBSS inside`,
};

const QueryBody = JSON.stringify({
query: `{
itemsByType(type:any){
id
bsgCategoryId
name
shortName
basePrice
normalizedName
types
width
height
avg24hPrice
wikiLink
changeLast48h
changeLast48hPercent
low24hPrice
high24hPrice
lastLowPrice
gridImageLink
iconLink
updated
traderPrices {
price
currency
priceRUB
trader {
name
const doFetchItems = async () => {

// Get the user selected language
const language = await langCode();

// Format the query for item fetching
const QueryBody = JSON.stringify({
query: `{
items(lang: ${language}) {
id
bsgCategoryId
name
shortName
basePrice
normalizedName
types
width
height
avg24hPrice
wikiLink
changeLast48h
changeLast48hPercent
low24hPrice
high24hPrice
lastLowPrice
gridImageLink
iconLink
updated
traderPrices {
price
currency
priceRUB
trader {
name
}
}
}
sellFor {
source
price
priceRUB
requirements {
type
value
sellFor {
source
price
priceRUB
requirements {
type
value
}
currency
}
currency
}
buyFor {
source
price
priceRUB
currency
requirements {
type
value
buyFor {
source
price
priceRUB
currency
requirements {
type
value
}
}
}
containsItems {
count
item {
id
containsItems {
count
item {
id
}
}
}
}
}`,
});
}`,
});

const doFetchItems = async () => {
const [itemData, itemGrids, itemProps] = await Promise.all([
fetch('https://api.tarkov.dev/graphql', {
method: 'POST',
Expand All @@ -83,7 +89,7 @@ const doFetchItems = async () => {
),
]);

const allItems = itemData.data.itemsByType.map((rawItem) => {
const allItems = itemData.data.items.map((rawItem) => {
let grid = false;

rawItem.itemProperties = itemProps[rawItem.id]?.itemProperties || {};
Expand Down
14 changes: 14 additions & 0 deletions src/modules/lang-helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Helper function to convert an i18n language to a two digit language code
import i18n from '../i18n';

export async function langCode() {
// Get the user selected language
var language = i18n.language;

// Convert to two digit language code
if (language === 'en-US') {
language = 'en';
}

return language;
};