Skip to main content
Version: 2.0.0

Localization

Localization is an important aspect of any Craft CMS project, allowing you to provide a more personalized experience for your users by offering your content in multiple languages. This guide will help you understand how to localize your store using the YSCP plugin.

Adding Translation Dictionaries

Your store can be localized like any other Craft CMS theme. This is done by adding PHP translation dictionaries in a translations/ subfolder of your project root.

Creating Translation Files

To create translation files for your project:

  1. Navigate to the translations folder: Ensure you have a translations folder in your project root. If it doesn't exist, create it.

  2. Create language subfolders: Within the translations folder, create subfolders for each language you want to support. For example, to support English and German, you would create the following structure:

root-directory
├── translations/
│ ├── en/
│ ├── de/
  1. Add translation files: Inside each language subfolder, create a PHP file for the translation category. For the YSCP plugin we are using the yui.php filename. Here’s an example structure:
### Example Translation File
<?php
return [
'welcomeMessage' => 'Welcome to our store!',
'productTitle' => 'Product Title',
'addToCart' => 'Add to Cart',
// Add more translations as needed
];

Plugin Translation Files

Our plugin uses the yui category for Craft CMS translations. This means that all translation strings in the plugin are referenced under this category.

Using Translation Strings

To use these translation strings in your files, you can use the Craft::t() function. Here’s an example:

{{ 'welcomeMessage'|t('yui', {params...}) }}

This will output the localized string for the welcomeMessage key from the yui category.

Supported Languages

YSCP currently supports the following languages:

  • sk: Slovak
  • cs: Czech
  • de: German
  • hu: Hungarian
  • en: English

Adding New Languages

If you need to add support for a new language:

  1. Create a new subfolder for the language in the translations directory.
  2. Add the yui.php file with the necessary translations.

For example, to add French support, you would create:

root-directory
├── translations/
│ ├── fr/
│ │ ├── yui.php

And populate the yui.php file with the appropriate translations.

Conclusion

By following these steps, you can easily localize your store and provide a better user experience for your international customers. If you have any questions or run into issues, please refer to the Craft CMS Localization Documentation for more detailed information.