Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. module.exports = function loader(source) {
  2. if (this.cacheable) this.cacheable();
  3.  
  4. let value = typeof source === 'string' ? JSON.parse(source) : source;
  5.  
  6. // Filter out smartling metadata.
  7. const metadata = value.smartling;
  8. if (metadata !== undefined) {
  9. const path = metadata.translate_paths.path.split('/')[1];
  10. delete value.smartling;
  11. Object.keys(value).forEach((key) => {
  12. value[key] = value[key][path];
  13. });
  14. }
  15.  
  16. value = JSON.stringify(value)
  17. .replace(/\u2028/g, '\\u2028')
  18. .replace(/\u2029/g, '\\u2029');
  19.  
  20. return `module.exports = ${value}`;
  21. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement