Cherrycake
ExamplesGithub
version 2.x alpha
version 2.x alpha
  • Introduction
  • Status
  • Changelog
  • Migration
  • Architecture
    • Basics
    • Modules
    • Classes
    • Lifecycle
      • Deep lifecycle
    • Performance
    • Security
    • Patterns
      • Files structure
    • Items
    • Server requirements
  • Guide
    • Getting started
      • Skeleton start
      • Docker start
    • Modules guide
    • Classes guide
    • Actions guide
      • Complex actions
      • Variable path components
      • Accept GET or POST parameters
      • Getting the URL of an action
      • Cached actions
      • Brute force attacks
    • Patterns guide
      • Passing variables to a pattern
      • Nested patterns
      • Cached patterns
    • Cache guide
      • Time To Live
      • Using cache
      • Lists
      • Queues
      • Pools
    • Database guide
      • Basic queries
      • Prepared queries
      • Cached queries
      • Cache key naming
      • Removing queries from cache
    • Items guide
      • Item cache
      • Item lists
      • Items custom filters
      • Items custom ordering
      • Mixing filters and ordering
      • Items with relationships
      • Items cache
    • HtmlDocument guide
    • Css and Javascript guide
      • Modules injecting CSS and JavaScript
    • Session guide
    • Login guide
      • Creating a complete login workflow
    • Locale guide
      • Multilingual texts
      • Domain based site localization
    • Log guide
      • Loading Log events from the database
    • Stats guide
      • Stats events with additional dimensions
      • Loading Stats events from the database
    • Janitor guide
      • Janitor tasks configuration files
    • Command line interface
    • Debugging
  • Reference
    • Core modules
      • Actions
        • Actions methods
      • Browser
      • Cache
        • Cache methods
      • Css
        • Css methods
      • Database
      • Email
      • Errors
      • HtmlDocument
        • HtmlDocument methods
      • ItemAdmin
      • Janitor
        • Janitor methods
      • Javascript
        • Javascript methods
      • Locale
        • Locale methods
      • Log
        • Log methods
      • Login
        • Login methods
      • Output
        • Output methods
      • Patterns
        • Patterns methods
      • Security
        • Security methods
      • Session
        • Session methods
      • Stats
        • Stats methods
      • SystemLog
      • TableAdmin
      • Translation
      • Validate
    • Core classes
      • Action
        • Action methods
        • Action properties
      • AjaxResponseJson
      • BasicObject
        • BasicObject methods
      • CacheProvider
        • CacheProvider methods
      • Color
      • DatabaseProvider
        • DatabaseProvider methods
      • DatabaseResult
        • DatabaseResult methods
        • DatabaseResult properties
      • DatabaseRow
      • Engine
        • Engine methods
        • Engine properties
      • Gradient
      • Item
        • Item methods
        • Item properties
      • Items
        • Items methods
        • Items properties
      • Image
      • JanitorTask
        • JanitorTask methods
        • JanitorTask properties
      • LogEvent
        • LogEvent methods
        • LogEvent Properties
      • LogEvents
        • LogEvents methods
      • Module
        • Module methods
        • Module properties
      • Response
      • Request
        • Request methods
      • RequestParameter
        • RequestParameter methods
      • RequestPathComponent
        • RequestPathComponent methods
      • Result
      • StatsEvent
        • StatsEvent properties
      • StatsEvents
        • StatsEvents methods
      • SystemLogEvent
        • SystemLogEvent methods
        • SystemLogEvent properties
      • SystemLogEvents
        • SystemLogEvents methods
  • Code conventions
  • License
  • Extras
Powered by GitBook
On this page
  • Text categories
  • Adding texts
  • Retrieving multilingual texts
  • Adding new languages
  • Variables in localized texts

Was this helpful?

  1. Guide
  2. Locale guide

Multilingual texts

Locale allows you to change the language of your app based on the selected locale.

PreviousLocale guideNextDomain based site localization

Last updated 5 years ago

Was this helpful?

To use the multilingual text features of the module, Cherrycake uses the cherrycake_locale_texts and cherrycake_locale_textcategories database tables with the following structure:

You can create this tables in your database by importing the locale.sql file you'll find in the , under the install/database directory.

Text categories

Optionally, texts in the database can be organized in categories, this might come in handy if you have lots of texts.

Add your text categories as rows to the cherrycake_locale_textcategories table, here's the columns specification:

  • code A unique identifier for the category, you'll be using it later to refer to this category in your code.

  • description Describe the kind of texts you'll be storing in this category.

Adding texts

Add translated texts as rows to the cherrycake_locale_texts table, with this column specification:

  • textCategories_id The category id assigned in the cherrycake_locale_textcategories table.

  • code A unique identifier for the text, you'll be using it later to refer to this text in your code.

  • description Describe this text, and the context where it will be used.

  • text_en The text in english.

Retrieving multilingual texts

id

code

description

1

general

General texts used throughout the site.

And the cherrycake_locale_texts tables like this:

id

textCategories_id

code

description

text_en

text_es

1

1

test

The typical test text used as an example.

Hello world

Hola mundo

You would access the text like this:

echo $e->Locale->getText("general/test");
$e->Locale->setLocale("spain");
echo $e->Locale->getText("general/test");
Hello world
Hola mundo

Adding new languages

To add new languages, just add new columns to the cherrycake_locale_texts table. The column name must follow the syntax text_<language code> For example, to add a text field for spanish, add the a field named text_es.

Variables in localized texts

You can use simple variables in localized texts to help you build more complex sentences, like this:

textCategories_id

code

text_en

text_es

1

newMessages

You have {numberOfMessages} new messages.

Tienes {numberOfMessages} mensajes nuevos.

echo $e->Locale->getText("general/newMessages", [
    "variables" => [
        "numberOfMessages" => 5
    ]
]);
You have 5 new messages.

To retrieve a text based on the current locale language, use the method. Imagine the cherrycake_locale_textcategories like this:

See this example working in the site.

See this example working in the site.

Locale
Cherrycake skeleton repository
Cherrycake documentation examples
Cherrycake documentation examples
Locale::getText