Git Product home page Git Product logo

sanity-localization-demo's Introduction

Very Demo

๐Ÿ‘‡

This is a very rough first draft of a localization plugin + field.

See the issues for some Sanity questions & problems I have!

sanity-localization-demo's People

Contributors

good-idea avatar

Watchers

James Cloos avatar  avatar

Forkers

elvarorn

sanity-localization-demo's Issues

Cannot compile wrapped DeskTool

In order to wrap the Desk Tool in a <Provider> element, I'm removing @sanity/desk-tool from the main list of plugins, and replacing it with localized, which exports a DeskTool wrapped in a provider.

When I start sanity, I get errors along the lines of:

Error in ./node_modules/@sanity/desk-tool/lib/pane/EditorPane.jsModule not found: Error: Part "part:@sanity/form-builder" not implemented by any plugins
 @ ./node_modules/@sanity/desk-tool/lib/pane/EditorPane.js 26:19-55
 @ ./node_modules/@sanity/desk-tool/lib/pane/Pane.js
 @ ./node_modules/@sanity/desk-tool/lib/DeskToolPanes.js
 @ ./node_modules/@sanity/desk-tool/lib/DeskTool.js
 @ ./node_modules/@sanity/desk-tool/lib/index.js
 @ ./plugins/localized/index.js
 @ ./plugins/localized (all:part:@sanity/base/tool)
 @ ./node_modules/@sanity/default-layout/lib/defaultLayoutRouter.js
 @ ./node_modules/@sanity/default-layout/lib/components/DefaultLayoutContainer.js (part:@sanity/base/root)
 @ ./node_modules/@sanity/base/lib/components/SanityRoot.js (part:@sanity/base/sanity-root)
 @ ./node_modules/@sanity/server/lib/browser/entry-dev.js
 @ multi ./node_modules/react-hot-loader/patch.js ./node_modules/normalize.css/normalize.css ./node_modules/@sanity/server/lib/browser/entry-dev.js

I discovered (by mistake) that if I start sanity with the default @sanity/desk-tool plugin, let it compile, and then replace it with localized, everything works as expected.

To recreate this:

  • run npm run start. You'll see the errors.
  • Cancel it, swap the keys of _plugins and plugins in sanity.json, then npm run start again.
  • While still running, swap the keys back to use localized.

Questions:

  • Is there an easier way to wrap everything in a provider?
  • Or, if exporting a wrapped DeskTool within the plugin (as I am doing) is the best approach, what's up with these errors and how can I get it going?

Better way to use the built-in Field component?

The function localizeField (see here) takes a standard field config and "localizes" it. (See it in use in the post schema)

usage:

	fields: [
		localizeField({
			name: 'title',
			title: 'Title',
			type: 'string',
		}),
		...
	]

It turns this field into an object with translations for each language. The above example turns into:

	fields: [
		{
			name: 'title',
			title: 'Title',
			type: 'object',
			fields: [
				{
					name: 'en',
					title: 'English',
					type: 'string',
				},
				{
					name: 'es',
					title: 'Spanish',
					type: 'string',
				},
				// ... and so on for other languages
			]
		}
		...
	]

This is done by copying the implementation of the core ObjectInput component, with the only difference being that it hides the input if it is not the current language.

As you can see in the function, it is literally just copied and pasted.

Question

Is there an easier way to render the child fields without needing to re-implement handleFieldChange and all of the other props?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.