BlueBase
  • 💧Introduction
  • Tutorial
    • 1. Getting Started
      • 1.1 Setup
      • 1.2 Add Plugins
      • 1.3 Create Custom Plugin
    • 2. Backend API
      • 2.1 Create Backend API
      • 2.2 Setup Apollo Client
      • 2.3 Generate Typescript Interfaces
    • 3. Create Screens
      • 3.1 Pending Tasks Screen
      • 3.2 Edit Task Screen
      • 3.3 Task Create Screen
      • 3.4 Tab Navigation
    • 4. CRUD Operations
      • 4.1 Creating Tasks
      • 4.2 Reading Tasks
      • 4.3 Updating Tasks
      • 4.4 Deleting Tasks
    • 5. Enhancements
      • 5.1 Internationalisation
      • 5.2 Theming
      • 5.3 Dynamic Images
      • 5.4 Settings & Configurations
      • User Management
  • Key Concepts
    • 🎡Lifecycle Events
    • â›Šī¸Main App Layout
    • 🔌Plugins
      • Plugin API
      • Register a Plugin
      • Making a Plugin Configurable
      • Developing an Analytics Plugin
      • Developing a Logger Plugin
      • Developing a Theme Plugin
    • 🚇Filters
    • 🎁Components
      • Components API
      • Registering a Component
      • Accessing Components
      • Higher Order Components
    • 🎨Themes
      • Consuming Selected Theme
      • Customise Themes
      • Customise Components
      • Theme Configs
      • Theme Structure
    • đŸŽ›ī¸Configs
  • API
    • 📈Analytics
    • 📔Logger
    • đŸ“ĻBlueBase Modules
    • Registry
  • Guides
    • âœ‚ī¸Code Splitting
    • đŸ‘ŊMigrating to V8
  • Components
    • ActivityIndicator
    • BlueBase
      • BlueBaseApp 📌
      • BlueBaseConsumer 📌
      • BlueBaseFilter 📌
      • ThemeConsumer 📌
    • Button
    • ComponentState 📌
    • EmptyState 📌
    • ErrorState 📌
    • Icons
      • Icon
      • DynamicIcon 📌
      • PluginIcon 📌
    • JsonSchema 📌
    • LoadingState 📌
    • Noop 📌
    • Observers
      • DataObserver 📌
      • ErrorObserver 📌
      • HoverObserver 📌
      • WaitObserver 📌
    • StatefulComponent 📌
    • Typography
    • View
Powered by GitBook
On this page
  • Step 1: Adding Language to the system
  • Step 2: Provide Translations
  • Step 3: Translating Strings

Was this helpful?

Export as PDF
  1. Tutorial
  2. 5. Enhancements

5.1 Internationalisation

Previous5. EnhancementsNext5.2 Theming

Last updated 3 years ago

Was this helpful?

Internationalisation is a big part of modern apps. BlueBase has built-in support for translations and right-to-left (RTL) text support.

Go you the Settings app, and select a language. If the language needs RTL, BlueBase will change orientation automatically.

Changing content direction on native requires app to be .

You can add support for any language you desire. Here are the steps on how to do this:

Step 1: Adding Language to the system

We support English and Urdu languages by default. If you need to add support for any other language just pass them to the locale.options object in your configs file, where the key of the object is the language code, and value is the language name.

configs.ts
export const configs = {

	'locale.options': {
		en: 'English',
		fr: 'French',
		ur: 'Ø§ŲØąØ¯ŲŲˆ',
	},

	// ... Other configs
};

Step 2: Provide Translations

Next, we have to create a dictionary, that the system can refer to when attempting to translate a string. The dictionary is an object where where original string is the key, and the translated version is the value.

src/lang/ur.ts
import { IntlMessages } from '@bluebase/core';

export const ur = (messages: IntlMessages) => ({
	...messages,

	'Title': 'ØšŲ†ŲˆØ§Ų†',
	'Description': 'ØĒ؁ØĩÛŒŲ„',
	'Pending': 'Ø˛ÛŒØą Ø§Ų„ØĒŲˆØ§ØĄ',
	'Completed': 'Ų…ÚŠŲ…Ų„',

	'Tasks': 'ÚŠØ§Ų…',
	'My Tasks': 'Ų…ÛŒØąÛŒ ŲšØ§ØŗÚŠØŗ',
	'No tasks': 'ÚŠŲˆØĻی ÚŠØ§Ų… Ų†ÛÛŒÚē',
	'Start by creating a new task': 'ایڊ Ų†ÛŒØ§ ÚŠØ§Ų… Ø¨Ų†Ø§ ÚŠØą Ø´ØąŲˆØš ÚŠØąÛŒÚē۔',
	'Create Task': 'ŲšØ§ØŗÚŠ Ø¨Ų†Ø§ØĻیÚē',
	'Edit Task': 'ŲšØ§ØŗÚŠ ØĒØąŲ…ÛŒŲ… ÚŠØąÛŒÚē',
	'Update Task': 'ŲšØ§ØŗÚŠ ØĒØ¯ŲˆÛŒŲ† ÚŠØąÛŒÚē',
});

export default ur;
src/lang/index.ts
import { ur } from './ur';

export const lang = {
	'bluebase.intl.messages.ur': ur,
};

The filter key for format to add translations is: bluebase.intl.messages.${language_code}. So for french language it would be bluebase.intl.messages.fr.

When we have all our language filters setup, we just need to add them to the filters object in the plugin.

src/index.ts
import { createPlugin } from '@bluebase/core';

import { ToDoAppIcon } from './components/ToDoAppIcon';
import { lang } from './lang';
import { routes } from './routes';
import { screens } from './screens';

export default createPlugin({
	key: 'tasks',
	name: 'Tasks',
	description: 'A todo app made with BlueBase framework.',

	filters: {
		...lang,
	},
	
	// ... other plugin properties
});

Step 3: Translating Strings

While we attempt to give built in conversion support for our official plugins, you may still need to do one additional step to convert your string to the current locale.

We'll take example of our TaskListEmptyState component. When you select a language different than English, you will note that the text is still not translated. Let's change that.

Go to your component and change to code to the following:

src/components/TaskListEmptyState/TaskListEmptyState.tsx
import { ComponentState, ComponentStateProps } from '@bluebase/components';
import { useIntl, useNavigation } from '@bluebase/core';
import React, { useCallback } from 'react';

export interface TaskListEmptyStateProps extends ComponentStateProps {}

export const TaskListEmptyState = (props: TaskListEmptyStateProps) => {
	const { __ } = useIntl();
	const { navigate } = useNavigation();

	const goToCreate = useCallback(() => navigate('CreateTask'), []);

	return (
		<ComponentState
			title={__('No tasks')}
			description={__('Start by creating a new task')}
			actionTitle={__('Create Task')}
			imageProps={{ resizeMode: 'contain' }}
			actionOnPress={goToCreate}
			actionProps={{ size: 'small', color: 'success', variant: 'outlined' }}
			{...props}
		/>
	);
};

TaskListEmptyState.displayName = 'TaskListEmptyState';

You will note that:

  • Line 2: We import useIntl hook from @bluebase/core.

  • Line 9: We extract the __ function from the useIntl() hook.

  • Line 15-17: We use the __ function to translate strings.

That's all! Since we have already provided translations to these strings in previous step, when you refresh the app you will now observe the text to be converted.

The way to do it is, we create a function that takes a dictionary as input, and we return that dictionary by appending our own translations to it. This is because the translations feature in BlueBase is built upon its feature.

Filters
restarted
iOS
Web
iOS
Web
iOS
Web