Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
@sanity/language-filter
Advanced tools
A Sanity plugin that supports filtering localized fields by language
A Sanity plugin that supports filtering localized fields by language
There are two popular methods of internationalization in Sanity Studio:
_id
This plugin adds features to the Studio to improve handling field-level translations.
For document-level translations you should use the @sanity/document-internationalization plugin.
sanity install @sanity/language-filter
Installing with sanity install
updates your sanity.json
to include this plugin. If installing with npm or yarn, ensure your plugins
array includes @sanity/language-filter
.
In order to know what languages are supported, this plugin needs to be set up with a config file that exports a few options.
This config file needs to implement the part part:@sanity/language-filter/config
, by adding the following lines to the parts
-section of your sanity.json
{
"name": "part:@sanity/language-filter/config",
"path": "./parts/languageFilterConfig.js"
}
Here's an example languageFilterConfig.js
file:
export default {
supportedLanguages: [
{id: 'nb', title: 'Norwegian (Bokmål)'},
{id: 'nn', title: 'Norwegian (Nynorsk)'},
{id: 'en', title: 'English'},
{id: 'es', title: 'Spanish'},
{id: 'arb', title: 'Arabic'},
{id: 'pt', title: 'Portuguese'},
//...
],
// Select Norwegian (Bokmål) by default
defaultLanguages: ['nb'],
// Only show language filter for document type `page` (schemaType.name)
documentTypes: ['page'],
filterField: (enclosingType, field, selectedLanguageIds) =>
!enclosingType.name.startsWith('locale') || selectedLanguageIds.includes(field.name),
}
supportedLanguages
is an array of languages with id
and title
. If your localized fields are defined using our recommended way described here (https://www.sanity.io/docs/localization), you probably want to share this list of supported languages between this config and your schema.defaultLanguages
(optional) is an array of strings where each entry must match an id
from the supportedLanguages
array. These languages will be listed by default and will not be possible to unselect. If no defaultLanguages
is configured, all localized fields will be selected by default.documentTypes
(optional) is an array of strings where each entry must match a name
from your document schemas. If defined, this property will be used to conditionally show the language filter on specific document schema types. If undefined, the language filter will show on all document schema types.filterField
is a function that must return true if the field should be displayed. It is passed the enclosing type (e.g the object type containing the localized fields, the field, and an array of the currently selected language ids.FAQs
A Sanity plugin that supports filtering localized fields by language
We found that @sanity/language-filter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 47 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.