Internationalization (i18n)
The @blocklet/uploader component is designed with a global audience in mind, offering robust support for multiple languages and text customization. This allows you to create a seamless user experience that feels native to your users, regardless of their location.
This guide explains how to switch between built-in languages and how to provide your own custom translations.
Switching Between Built-in Languages#
The component ships with pre-configured language packs for English (en) and Chinese (zh). The simplest way to change the display language is by using the locale prop.
Uploader with Chinese locale
import { Uploader } from '@blocklet/uploader/react';
function MyComponent() {
return <Uploader locale="zh" />;
}Setting locale="zh" will automatically translate the entire UI into Chinese. The default language is English (en).
Customizing Text and Adding New Languages#
For more advanced control, such as overriding specific text strings or adding support for a new language, you can provide a custom locale object to the Uploader. This is done through the coreProps.locale property, which gives you direct access to the underlying Uppy instance's configuration.
A locale object consists of a strings key, which contains all the text used in the UI.
Overriding Existing Strings#
You can easily change any text to better match your application's tone or terminology. For example, let's change the main drop hint.
First, import one of the base locale objects provided by the package, then merge your changes.
Customizing the drop hint text
import { Uploader } from '@blocklet/uploader/react';
import { locales } from '@blocklet/uploader/i18n';
import merge from 'lodash/merge';
// Create a deep copy of the default English locale
const customEnglishLocale = merge({}, locales.en);
// Override the specific string you want to change
customEnglishLocale.strings.dropHint = 'Drop your awesome files here!';
function MyComponent() {
return (
<Uploader
coreProps={{
locale: customEnglishLocale,
}}
/>
);
}Adding a New Language#
To add a language not included by default, you'll need to create a complete locale object. The recommended approach is to import a base locale from Uppy's extensive collection and then merge it with translations for the custom strings specific to @blocklet/uploader.
Here is an example of how you might create a basic French locale:
Adding a French locale
import { Uploader } from '@blocklet/uploader/react';
import fr_FR from '@uppy/locales/lib/fr_FR'; // Base Uppy locale
import merge from 'lodash/merge';
// Create a custom locale object by merging Uppy's French pack
// with translations for our custom strings.
const customFrenchLocale = merge({}, fr_FR, {
strings: {
// Custom strings from @blocklet/uploader
aiKitRequired: 'Veuillez installer et configurer le kit AI',
aiImageGenerate: 'Générer',
aiImageGenerating: 'Génération en cours...',
browseFiles: 'parcourir les fichiers',
browseFolders: 'parcourir les dossiers',
dropHint: 'Déposez vos fichiers ici',
// ... and so on for all other custom strings
},
});
function MyComponent() {
return (
<Uploader
coreProps={{
locale: customFrenchLocale,
}}See all 3 lines
Customizable Strings#
While @blocklet/uploader inherits most of its strings from the Uppy ecosystem, it also adds several custom strings for its unique features. Below is a list of these specific keys that you can override.
Key | Default (English) Description |
|---|---|
| Text shown when the AI Image plugin is used without AI Kit being configured. |
| Button text to confirm the use of a selected AI-generated image. |
| A hint asking the user to select an image. |
| Label for the AI image prompt input field. |
| Placeholder text for the prompt input. |
| Label for the image size selector. |
| Label for the image model selector. |
| Label for the number of images to generate. |
| Button text to start image generation. |
| Text displayed while images are being generated. |
| Text for the 'browse folders' link. |
| The main text displayed in the drop area. |
| Drop area text when both files and folders can be browsed. |
| Drop area text when only files can be browsed. |
| Drop area text when only folders can be browsed. |
| Text for the 'Back' or 'Cancel' button. |
| Text shown when checking the Media Kit status. |
| Warning message for images that don't meet the required aspect ratio. |
| Message shown while the image editor is loading. |
| Error message when a remote file (e.g., from a URL) fails to download. |
| Message shown when |
| Prefix for the list of allowed file types. |
| General initialization error message. |
For a complete list of all strings available for translation, please refer to the official Uppy locale documentation.
By leveraging this flexible i18n system, you can ensure your application's file uploader is accessible and intuitive for all users. For more details on Uppy's configuration, see the Integration with Uppy guide.