Skip to content

Instantly share code, notes, and snippets.

@robstoll
Last active December 19, 2019 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robstoll/e446eaae27759c51eb0626ada64d4a87 to your computer and use it in GitHub Desktop.
Save robstoll/e446eaae27759c51eb0626ada64d4a87 to your computer and use it in GitHub Desktop.
update translations for worpress
var wpblocks = wp.data.select('core/block-editor').getBlocks(); a.split('\n').map(x => x.split(';')).filter(x => x[0]!='').forEach(x => {
var blocks = wpblocks.filter(y => y.attributes.content != null && y.attributes.content.replace(/\n/g, ' ') == x[0]);
if (blocks.length > 1) {
console.error("zu viele", blocks);
} else if(blocks.length == 1) {
wp.data.dispatch('core/block-editor').updateBlockAttributes(blocks[0].clientId, {'content': x[1] })
} else if(wp.data.select('core/editor').getEditedPostAttribute('title') == x[0]) {
wp.data.dispatch('core/editor').editPost({ title: x[1] })
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment