This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugins): i18n support inside plugins (#930)
- Loading branch information
Showing
4 changed files
with
154 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { GluegunToolbox } from "gluegun"; | ||
|
||
module.exports = (toolbox: GluegunToolbox) => { | ||
toolbox.languages = {}; | ||
|
||
/** | ||
* Returns list of filenames from directory | ||
*/ | ||
toolbox.languages.getDirLocalesList = async (directoryPath) => { | ||
return (await toolbox.filesystem.listAsync(directoryPath)) || []; | ||
}; | ||
|
||
/** | ||
* Returns locales map for specified directory | ||
*/ | ||
toolbox.languages.getLocalesMap = async (directoryPath) => { | ||
const path = require("path"); | ||
const languageKeys = await toolbox.languages.getDirLocalesList( | ||
directoryPath | ||
); | ||
const resultMap = {}; | ||
languageKeys.forEach((languageKey) => { | ||
resultMap[languageKey] = toolbox.filesystem.read( | ||
path.join(directoryPath, languageKey), | ||
"json" | ||
); | ||
}); | ||
return resultMap; | ||
}; | ||
|
||
toolbox.languages.mergeLocalesMap = async (baseMap, newMap) => { | ||
const { merge } = require("lodash"); | ||
const newMapKeys = Object.keys(newMap); | ||
newMapKeys.forEach((newMapKey) => { | ||
baseMap[newMapKey] = merge(baseMap[newMapKey], newMap[newMapKey]); | ||
}); | ||
}; | ||
|
||
/** | ||
* Returns directory paths for installed plugins | ||
*/ | ||
toolbox.languages.getPluginsLocalesPaths = async ({ | ||
pluginsConfig, | ||
rootDirectory, | ||
}: any) => { | ||
const path = require("path"); | ||
const pluginsRootDirectory = | ||
rootDirectory || ".shopware-pwa/pwa-bundles-assets"; | ||
const localesPaths = []; | ||
if (pluginsConfig) { | ||
const pluginNames = Object.keys(pluginsConfig); | ||
pluginNames.forEach((pluginName) => { | ||
if (!pluginsConfig[pluginName]) return; | ||
localesPaths.push( | ||
path.join(pluginsRootDirectory, pluginName, "locales") | ||
); | ||
}); | ||
} | ||
return localesPaths; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8f9638d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to following URLs: