npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sanity-plugin-tos

v1.0.0

Published

This is a **Sanity Studio v3** plugin for translating Sanity documents using the TranslationOS API.

Downloads

276

Readme

TranslationOS Sanity Plugin

This is a Sanity Studio v3 plugin for translating Sanity documents using the TranslationOS API.

Please note that this plugin requires the Sanity document-internationalization plugin.

Installation

Add the plugin as a dependency in your Sanity Studio project by running:

npm install sanity-plugin-tos

Configuration

Add it as a plugin in your sanity.config.ts (or .js).

The following configuration example shows how to add the plugin and share the list of languages and the active document types with the document internationalization plugin. It is recommended that the language identifiers are taken from the list of TOS supported languages. Use of non-supported language identifiers is possible but must be agreed with Translated in advance.

import {defineConfig} from 'sanity'
import {StructureBuilder} from "sanity/structure";
import {tosPlugin} from 'sanity-plugin-tos'

const languages = [
  {id: 'en-US', title: 'English'},
  {id: 'fr-FR', title: 'French'},
  {id: 'de-DE', title: 'German'},
  {id: 'es-ES', title: 'Spanish'},
];
const documentTypes = ['post', 'author']

export default defineConfig({
  //... other configuration
  plugins: [
    // ... other plugins
    documentInternationalization({
      supportedLanguages: languages,
      schemaTypes: documentTypes,
      weakReferences: true,
    }),
    structureTool({
      defaultDocumentNode: (S: StructureBuilder, {schemaType}: DefaultDocumentNodeContext) => {
        if (documentTypes.includes(schemaType)) {
          return S.document().views([
            S.view.form(),
            tosPlugin(S, {
              env: 'staging',
              apiKey: 'TOS_API_KEY',
              supportedLanguages: languages,
              sourceLanguage: 'en-US',
            })
          ])
        }
      }
    }),
    //... other plugins
  ],
})

The tosPlugin function returns a ComponentViewBuilder that should be added to the editor views for specific document types. It is of course highly recommended to add the view only to the document types that have been configured in the document internationalization plugin. The function takes the following options:

  • env - the environment of the TOS API, either staging, sandbox or production
  • apiKey - your API key for the above TOS API environment
  • supportedLanguages - the list of languages to be supported by the TOS plugin, the array has the same structure of the one used in the document internationalization plugin.
  • sourceLanguage - the language identifier of the language to be considered as source language among those listed in the supportedLanguages array. The remaining will be treated as target languages.

TOS plugin options in Sanity Studio's schema

TOS plugin specific options can be set in the schema definition of a field and are grouped in a tosProperties block. The following options are currently available:

  • exclude - a boolean value, set it to true to exclude the field from being sent to the TOS API for translation.
// ... other field definitions
defineField({
  name: 'fullname',
  type: 'string',
  title: 'Full Name',
  options: {
    tosProperties: {
      exclude: true,
    }
  }
})
// ... other field definitions

What is translated by default

The plugin will send to translation all document fields of type string, text, slug or block.

Fields of type array and object will be recursively traversed.

Fields marked as hidden and/or readOnly will be excluded from translation.

The plugin will also exclude the fields excluded via a tosProperties block with exclude set to true as indicated in the previous section.

While inspecting the document JSON structure, the plugin will also exclude the Sanity metadata fields (such as _id, _rev, _type, createdAt, etc.).

Block content

The block field type is highly customizable and can be redefined in the project schema. The plugin supports the following block features:

  • bold, italic, underline, strikethrough, code and link spans
  • headings and blockquote styles
  • bullet and numbered lists
  • references to images