l-min-components 1.0.750 → 1.0.757
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -21,13 +21,13 @@ import { DebounceInput } from "react-debounce-input";
|
|
|
21
21
|
*
|
|
22
22
|
*/
|
|
23
23
|
const LanguageDropdown = ({ languageDropdown, setLanguageDropdown }) => {
|
|
24
|
-
const { setGeneralData, generalData, setDefaultLang, findText } =
|
|
24
|
+
const { setGeneralData, generalData, defaultLang, setDefaultLang, findText } =
|
|
25
25
|
useContext(OutletContext);
|
|
26
26
|
const [filteredData, setFilteredData] = useState([]);
|
|
27
27
|
const [isSearch, setIsSearch] = useState(false);
|
|
28
28
|
const containerRef = useRef(null);
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
console.log("object", defaultLang)
|
|
31
31
|
|
|
32
32
|
const handleFilter = (event) => {
|
|
33
33
|
const searchWord = event.target.value;
|
|
@@ -6,6 +6,7 @@ import { ArrowDownIcon } from "./assets/svg/arrow-down";
|
|
|
6
6
|
import ButtonComponent from "../button";
|
|
7
7
|
import { useLocation, useNavigate } from "react-router-dom";
|
|
8
8
|
import usFlag from "../../assets/images/usFlag.png";
|
|
9
|
+
import koreanFlag from "../../assets/images/koreaFlag.png";
|
|
9
10
|
import { OutletContext } from "..";
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from "react";
|
|
2
|
-
import loadTranslations from "
|
|
1
|
+
import React, { useCallback, useEffect, useState } from "react";
|
|
2
|
+
import loadTranslations from "./utils/translation";
|
|
3
3
|
|
|
4
4
|
const useTranslation = () => {
|
|
5
5
|
const value = localStorage.getItem("defaultLang");
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// import Tabletop from "tabletop";
|
|
2
|
+
import Papa from "papaparse";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Loads translation data from a Google Sheet URL into a structured object.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} sheetUrl - The URL of the published Google Sheet.
|
|
8
|
+
* @param {string[]} languages - Array of language codes (e.g., ['es', 'fr']) to include in the result.
|
|
9
|
+
* @returns {Promise<Object>} A Promise that resolves to an object with English keys and translated values.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const protoUrl =
|
|
13
|
+
"https://docs.google.com/spreadsheets/d/e/2PACX-1vSvUIA_1eqpANaRTXafwYkh0y7ZYfbgvlHeLNjti21yjdtJjy6Fjk7pAuQjODROqT3uALC2Aq_odZy4/pub?gid=0&single=true&output=csv";
|
|
14
|
+
|
|
15
|
+
async function loadTranslations(sheetUrl = protoUrl, language = "") {
|
|
16
|
+
try {
|
|
17
|
+
// 1. Fetch data from the Google Sheet
|
|
18
|
+
const response = await fetch(sheetUrl);
|
|
19
|
+
|
|
20
|
+
// Check if the request was successful
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
`Failed to fetch from Google Sheet: ${response.status} ${response.statusText}`
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const csvData = await response.text();
|
|
28
|
+
|
|
29
|
+
// 2. Parse CSV data (handling quoted fields with commas)
|
|
30
|
+
const parseResult = Papa.parse(csvData, { header: true });
|
|
31
|
+
|
|
32
|
+
// Check for parsing errors
|
|
33
|
+
if (parseResult.errors.length > 0) {
|
|
34
|
+
throw new Error(`Failed to parse CSV data: ${parseResult.errors}`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const rows = parseResult.data;
|
|
38
|
+
|
|
39
|
+
// 3. Identify the English column and language columns
|
|
40
|
+
const headers = Object.keys(rows[0]);
|
|
41
|
+
|
|
42
|
+
const englishColumnIndex = headers.indexOf("en"); // Using 'en' instead of 'English' based on your feedback
|
|
43
|
+
|
|
44
|
+
// Ensure English column exists
|
|
45
|
+
if (englishColumnIndex === -1) {
|
|
46
|
+
throw new Error("English column not found in Google Sheet");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// if language exists
|
|
50
|
+
if (!headers.includes(language))
|
|
51
|
+
throw new Error(language.concat(" translation not found"));
|
|
52
|
+
|
|
53
|
+
const translations = {};
|
|
54
|
+
for (let row of rows) {
|
|
55
|
+
translations[row.en.trim().replace(/\r\n|\r/g, "\n")] = row[language];
|
|
56
|
+
}
|
|
57
|
+
return translations;
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.error("Error loading translations:", error);
|
|
60
|
+
return {};
|
|
61
|
+
// throw error; // Rethrow for handling elsewhere
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export default loadTranslations;
|