mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
* feat(api-v4): new /faq route added * refactor(server): change of function name in libs/content.js
27 lines
793 B
JavaScript
27 lines
793 B
JavaScript
import _ from 'lodash';
|
|
import path from 'path';
|
|
import common from '../../common';
|
|
|
|
export const CONTENT_CACHE_PATH = path.join(__dirname, '/../../../content_cache/');
|
|
|
|
function walkContent (obj, lang) {
|
|
_.each(obj, (item, key, source) => {
|
|
if (_.isPlainObject(item) || _.isArray(item)) {
|
|
walkContent(item, lang);
|
|
} else if (_.isFunction(item) && item.i18nLangFunc) {
|
|
source[key] = item(lang);
|
|
}
|
|
});
|
|
}
|
|
|
|
export function localizeContentData (data, langCode) {
|
|
const dataClone = _.cloneDeep(data);
|
|
walkContent(dataClone, langCode);
|
|
return dataClone;
|
|
}
|
|
|
|
export function getLocalizedContentResponse (langCode) {
|
|
const localizedContent = localizeContentData(common.content, langCode);
|
|
return `{"success": true, "data": ${JSON.stringify(localizedContent)}}`;
|
|
}
|