Skip to content
Open
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 src/components/calculations/calculations.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function Calculations() {

var shortCode = "en";
if (i18n.resolvedLanguage) {
shortCode = i18n.resolvedLanguage.split('-')[0];
shortCode = Utils.getFlyffLanguageShortCodeFromLanguage(i18n);
}

function setTarget(index) {
Expand Down
3 changes: 2 additions & 1 deletion src/components/calculations/charts/barchart.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Bar } from "react-chartjs-2";
import { useTranslation } from "react-i18next";
import { getFlyffLanguageShortCodeFromLanguage } from '../../../flyff/flyffutils'

import HoverInfo from "../../shared/hoverinfo";

Expand All @@ -8,7 +9,7 @@ function BarChart({ chartData, title, info, label, sourceLink, percentage, highl

var shortCode = "en";
if (i18n.resolvedLanguage) {
shortCode = i18n.resolvedLanguage.split('-')[0];
shortCode = getFlyffLanguageShortCodeFromLanguage(i18n);
}

function getMinValue(ctx) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/calculations/charts/linechart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function LineChart({ chartData, title, info, label, sourceLink, skillId = 0 }) {

var shortCode = "en";
if (i18n.resolvedLanguage) {
shortCode = i18n.resolvedLanguage.split('-')[0];
shortCode = Utils.getFlyffLanguageShortCodeFromLanguage(i18n);
}

const skillProp = skillId > 0 ? Utils.getSkillById(skillId) : null;
Expand Down
2 changes: 1 addition & 1 deletion src/components/equipment/itemedit/itemedit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function ItemEdit({ itemElem }) {
const { i18n } = useTranslation();
var shortCode = "en";
if (i18n.resolvedLanguage) {
shortCode = i18n.resolvedLanguage.split('-')[0];
shortCode = Utils.getFlyffLanguageShortCodeFromLanguage(i18n);
}

if (itemElem == null) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/equipment/itemedit/petwindow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function PetWindow({ raisedPetDefinition, petLevels, editable = false, onEditLev
const { i18n } = useTranslation();
var shortLanguageCode = "en";
if (i18n.resolvedLanguage) {
shortLanguageCode = i18n.resolvedLanguage.split('-')[0];
shortLanguageCode = Utils.getFlyffLanguageShortCodeFromLanguage(i18n);
}

function toggleTooltip(enabled) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/shared/search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function Search() {

var shortCode = "en";
if (i18n.resolvedLanguage) {
shortCode = i18n.resolvedLanguage.split('-')[0];
shortCode = Utils.getFlyffLanguageShortCodeFromLanguage(i18n);
}

if (!isSearchOpen) {
Expand Down
3 changes: 2 additions & 1 deletion src/components/skillsandbuffs/skilltreeicon.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useRef } from 'react';
import { useTooltip } from '../../tooltipcontext';
import { createTooltip } from '../../flyff/flyfftooltip';
import { getFlyffLanguageShortCodeFromLanguage } from '../../flyff/flyffutils';
import { useTranslation } from "react-i18next";

function SkillTreeIcon({ skill, disabled, level, clickHandle, rightClickHandle }) {
Expand All @@ -9,7 +10,7 @@ function SkillTreeIcon({ skill, disabled, level, clickHandle, rightClickHandle }
const { i18n } = useTranslation();
var shortCode = "en";
if(i18n.resolvedLanguage) {
shortCode = i18n.resolvedLanguage.split('-')[0];
shortCode = getFlyffLanguageShortCodeFromLanguage(i18n);
}

const levelText = level == skill.levels.length ? "MAX" : level;
Expand Down
8 changes: 4 additions & 4 deletions src/flyff/flyfftooltip.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function setupItem(itemElem, i18n) {
const itemProp = itemElem.itemProp;
var shortLanguageCode = "en";
if (i18n.resolvedLanguage) {
shortLanguageCode = i18n.resolvedLanguage.split('-')[0];
shortLanguageCode = Utils.getFlyffLanguageShortCodeFromLanguage(i18n);
}

const isUltimate = itemProp.rarity == "ultimate";
Expand Down Expand Up @@ -488,7 +488,7 @@ function setupSkill(skill, i18n) {
const out = [];
var shortLanguageCode = "en";
if (i18n.resolvedLanguage) {
shortLanguageCode = i18n.resolvedLanguage.split('-')[0];
shortLanguageCode = Utils.getFlyffLanguageShortCodeFromLanguage(i18n);
}

const skillLevel = Context.player.skillLevels[skill.id] ?? skill.levels.length;
Expand Down Expand Up @@ -706,7 +706,7 @@ function setupPartySkill(partySkill, i18n) {
const out = []
var shortLanguageCode = 'en'
if (i18n.resolvedLanguage) {
shortLanguageCode = i18n.resolvedLanguage.split('-')[0]
shortLanguageCode = Utils.getFlyffLanguageShortCodeFromLanguage(i18n);
}

out.push(<span style={{ color: "#2fbe6d", fontWeight: 600 }}>{partySkill.name[shortLanguageCode] ?? partySkill.name.en}</span>);
Expand All @@ -724,7 +724,7 @@ function setupHousingNpc(housingNpc, i18n) {
const out = [];
var shortLanguageCode = "en";
if (i18n.resolvedLanguage) {
shortLanguageCode = i18n.resolvedLanguage.split('-')[0];
shortLanguageCode = Utils.getFlyffLanguageShortCodeFromLanguage(i18n);
}

out.push(<span style={{ color: "#2fbe6d", fontWeight: 600 }}>{housingNpc.name[shortLanguageCode] ?? housingNpc.name.en}</span>);
Expand Down
29 changes: 27 additions & 2 deletions src/flyff/flyffutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ export const ATTACK_FLAGS = {
REGION: 1 << 15 // AoE skill.
};

export const LANGUAGE_CODE_MAP = {
"zh-tw": "tw",
"zh-cn": "cns",
"zh": "cns",
"pt-br": "br",
};

export function getClassById(id) {
return classes[id];
}
Expand Down Expand Up @@ -123,7 +130,7 @@ export function getStatNameByIdOrDefault(id, i18n) {

var shortLanguageCode = "en";
if (i18n.resolvedLanguage) {
shortLanguageCode = i18n.resolvedLanguage.split('-')[0];
shortLanguageCode = getFlyffLanguageShortCodeFromLanguage(i18n);
}

return stat[shortLanguageCode] ?? stat.en;
Expand Down Expand Up @@ -412,7 +419,7 @@ export function getStatAwakeTitle(itemElem, i18n) {

var shortLanguageCode = "en";
if (i18n.resolvedLanguage) {
shortLanguageCode = i18n.resolvedLanguage.split('-')[0];
shortLanguageCode = getFlyffLanguageShortCodeFromLanguage(i18n);
}


Expand Down Expand Up @@ -467,3 +474,21 @@ export function getGuid() {
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
);
}

/**
* Get the Flyff language short code based on the resolved i18n language.
*
* @param {object} i18n Localization
* @returns {string} The mapped Flyff language short code, or the base language, or "en" as fallback.
*/
export function getFlyffLanguageShortCodeFromLanguage(i18n) {
const lang = i18n.resolvedLanguage.toLowerCase();

// Return mapped code if available
if (LANGUAGE_CODE_MAP[lang]) {
return LANGUAGE_CODE_MAP[lang];
}

const baseLang = lang.split("-")[0];
return baseLang || "en";
}