GithubHelp home page GithubHelp logo

translate-plugin's Introduction

Translation plugin

Enables multi-lingual sites.

Selecting a Language

Different languages can be set up in the admin panel using the Settings → Sites area. Each site should use a different locale to be considered a language.

The visitor can select a language by prefixing the language code to the URL or using a dedicated hostname. For example:

  • http://website.tld/ will display the site in the default language
  • http://website.tld/ru/ will display the site in Russian
  • http://website.tld/fr/ will display the site in French

License

This plugin is an official extension of the October CMS platform and is free to use if you have a platform license. See EULA license for more details.

Installation

To install using October CMS v3.1 or above:

php artisan plugin:install rainlab.translate

To install using October CMS v3.0 and below:

php artisan plugin:install rainlab.translate --want="^1.0"

Upgrading from v1 to v2

If you are upgrading from version 1 of this plugin, view the upgrade guide.

Language Picker Component

A visitor can select their chosen language using the native SitePicker component that is included in the October CMS core. This component will display a simple dropdown that changes the page language depending on the selection.

title = "Home"
url = "/"

[sitePicker]
==

<h3>{{ 'Please select your language:'|_ }}</h3>
<select class="form-control" onchange="window.location.assign(this.value)">
    {% for site in sitePicker.sites %}
        <option value="{{ site.url }}" {{ this.site.code == site.code ? 'selected' }}>{{ site.name }}</option>
    {% endfor %}
</select>

If translated, the text above will appear as whatever language is selected by the user. The dropdown is very basic and is intended to be restyled. A simpler example might be:

<p>
    Switch language to:

    {% for site in sitePicker.sites %}
        <a href="{{ site.url }}">{{ site.name }}</a>
    {% endfor %}
</p>

Message Translation

Message or string translation is the conversion of adhoc strings used throughout the site. A message can be translated with parameters.

{{ 'site.name'|_ }}

{{ 'Welcome to our website!'|_ }}

{{ 'Hello :name!'|_({ name: 'Friend' }) }}

A message can also be translated for a choice usage.

{{ 'There are no apples|There are :number applies!'|__(2, { number: 'two' }) }}

Or you set a locale manually by passing a second argument.

{{ 'this is always english'|_({}, 'en') }}

Themes can provide default values for these messages by defining a translate key in the theme.yaml file, located in the theme directory.

name: My Theme
# [...]

translate:
    en:
        site.name: 'My Website'
        nav.home: 'Home'
        nav.video: 'Video'
        title.home: 'Welcome Home'
        title.video: 'Screencast Video'

You may also define the translations in a separate file, where the path is relative to the theme. The following definition will source the default messages from the file config/lang.yaml inside the theme.

name: My Theme
# [...]

translate: config/lang.yaml

This is an example of config/lang.yaml file with two languages:

en:
    site.name: 'My Website'
    nav.home: 'Home'
    nav.video: 'Video'
    title.home: 'Welcome Home'
hr:
    site.name: 'Moje web stranice'
    nav.home: 'Početna'
    nav.video: 'Video'
    title.home: 'Dobrodošli'

You may also define the translations in a separate file per locale, where the path is relative to the theme. The following definition will source the default messages from the file config/lang-en.yaml inside the theme for the english locale and from the file config/lang-fr.yaml for the french locale.

name: My Theme
# [...]

translate:
    en: config/lang-en.yaml
    fr: config/lang-fr.yaml

This is an example for the config/lang-en.yaml file:

site.name: 'My Website'
nav.home: 'Home'
nav.video: 'Video'
title.home: 'Welcome Home'

In order to make these default values reflected to your frontend site, go to Settings -> Translate messages in the backend and hit Scan for messages. They will also be loaded automatically when the theme is activated.

The same operation can be performed with the translate:scan artisan command. It may be worth including it in a deployment script to automatically fetch updated messages:

php artisan translate:scan

Add the --purge option to clear old messages first:

php artisan translate:scan --purge

Content & Mail Template Translation

This plugin activates a feature in the CMS that allows content & mail template files to use language suffixes, for example:

  • welcome.htm will contain the content or mail template in the default language.
  • welcome-ru.htm will contain the content or mail template in Russian.
  • welcome-fr.htm will contain the content or mail template in French.

Model Translation

Models can have their attributes translated by using the RainLab\Translate\Behaviors\TranslatableModel behavior and specifying which attributes to translate in the class.

class User
{
    public $implement = [
        \RainLab\Translate\Behaviors\TranslatableModel::class
    ];

    public $translatable = ['name'];
}

The attribute will then contain the default language value and other language code values can be created by using the translateContext() method.

$user = User::first();

// Outputs the name in the default language
echo $user->name;

$user->translateContext('fr');

// Outputs the name in French
echo $user->name;

You may use the same process for setting values.

$user = User::first();

// Sets the name in the default language
$user->name = 'English';

$user->translateContext('fr');

// Sets the name in French
$user->name = 'Anglais';

The lang() method is a shorthand version of translateContext() and is also chainable.

// Outputs the name in French
echo $user->lang('fr')->name;

This can be useful inside a Twig template.

{{ user.lang('fr').name }}

There are ways to get and set attributes without changing the context.

// Gets a single translated attribute for a language
$user->getAttributeTranslated('name', 'fr');

// Sets a single translated attribute for a language
$user->setAttributeTranslated('name', 'Jean-Claude', 'fr');

Theme Data Translation

It is also possible to translate theme customisation options. Just mark your form fields with translatable property and the plugin will take care about everything else:

tabs:
    fields:
        website_name:
            tab: Info
            label: Website Name
            type: text
            default: Your website name
            translatable: true

Fallback Attribute Values

By default, untranslated attributes will fall back to the default locale. This behavior can be disabled by calling the noFallbackLocale method when reading the value.

$user = User::first();

$user->noFallbackLocale()->lang('fr');

// Returns NULL if there is no French translation
$user->name;

When writing the value, the fallback value is determined when the translated value matches the default value. In these cases, the translated value is considered untranslated and not stored.

Locale Attribute Value Is Stored
en title Hello World Yes (Default)
fr title Hello World No
de title Hallo Welt Yes

For example, if the en default locale stores the message as "Hello World" and the fr locale value is also "Hello World", then the fr value is not stored. The fr value is accessed using the fallback value taken from en.

You may disable this behavior by passing the $transatable attribute value as an array. The first value is the attribute name, the other values represent options, in this case setting the option fallback to false.

public $translatable = [
    ['title', 'fallback' => false]
];

This above definition will force the title attribute value to be duplicated and stored across all locales.

Indexed Attributes

Translatable model attributes can also be declared as an index by passing the $transatable attribute value as an array. The first value is the attribute name, the other values represent options, in this case setting the option index to true.

public $translatable = [
    'name',
    ['slug', 'index' => true]
];

Once an attribute is indexed, you may use the transWhere method to apply a basic query to the model.

Post::transWhere('slug', 'hello-world')->first();

The transWhere method accepts a third argument to explicitly pass a locale value, otherwise it will be detected from the environment.

Post::transWhere('slug', 'hello-world', 'en')->first();

URL Translation

Pages in the CMS support translating the URL property. Assuming you have 3 languages set up:

  • en: English
  • fr: French
  • ru: Russian

There is a page with the following content:

url = "/contact"

[viewBag]
localeUrl[ru] = "/контакт"
==
<p>Page content</p>

The word "Contact" in French is the same so a translated URL is not given, or needed. If the page has no URL override specified, then the default URL will be used. Pages will not be duplicated for a given language.

  • /fr/contact - Page in French
  • /en/contact - Page in English
  • /ru/контакт - Page in Russian
  • /ru/contact - 404

Translating URLs in Twig

The localeUrl method will replace the route prefix on a URL from one locale to another. For example, converting the current request URL from en to de.

{{ this.request.url|localeUrl('de') }}

The localePage will return a translated URL for a CMS page. It takes a locale (first argument) and page parameters (second argument).

{{ 'blog/post'|localePage('de', { slug: 'foobar' }) }}

URL Parameter Translation

It's possible to translate URL parameters by listening to the cms.sitePicker.overrideParams event, which is fired when discovering language URLs.

Event::listen('cms.sitePicker.overrideParams', function($page, $params, $oldSite, $newSite) {
    if ($page->baseFileName == 'your-page-filename') {
        return MyModel::translateParams($params, $oldSite->hard_locale, $newSite->hard_locale);
    }
});

In MyModel, one possible implementation might look like this:

public static function translateParams($params, $oldLocale, $newLocale)
{
    $newParams = $params;
    foreach ($params as $paramName => $paramValue) {
        $records = self::transWhere($paramName, $paramValue, $oldLocale)->first();
        if ($records) {
            $records->translateContext($newLocale);
            $newParams[$paramName] = $records->$paramName;
        }
    }
    return $newParams;
}

Query String Translation

It's possible to translate query string parameters by listening to the cms.sitePicker.overrideQuery event, which is fired when switching languages.

Event::listen('cms.sitePicker.overrideQuery', function($page, $params, $oldSite, $newSite) {
    if ($page->baseFileName == 'your-page-filename') {
        return MyModel::translateParams($params, $oldSite->hard_locale, $newSite->hard_locale);
    }
});

For a possible implementation of the MyModel::translateParams method look at the example under URL parameter translation from above.

Extend Theme Scan

Event::listen('rainlab.translate.themeScanner.afterScan', function (ThemeScanner $scanner) {
    // ...
});

Settings Model Translation

It's possible to translate your settings model like any other model. To retrieve translated values use:

Settings::instance()->getAttributeTranslated('your_attribute_name');

Conditionally Extending Plugins

Models

It is possible to conditionally extend a plugin's models to support translation by placing an @ symbol before the behavior definition. This is a soft implement will only use TranslatableModel if the Translate plugin is installed, otherwise it will not cause any errors.

/**
 * Post Model for the blog
 */
class Post extends Model
{
    // [...]

    /**
     * @var array implement the TranslatableModel behavior softly.
     */
    public $implement = ['@'.\RainLab\Translate\Behaviors\TranslatableModel::class];

    /**
     * @var array translatable attributes, if available.
     */
    public $translatable = ['title'];

    // [...]
}

The back-end forms will automatically detect the presence of translatable fields and replace their controls for multilingual equivalents.

User Interface

Switching Locales

Users can switch between locales by clicking on the site selection menu in the backend panel. This will add a _site_id query value to the URL, allowing for multiple browser tabs to be used.

translate-plugin's People

Contributors

acasar avatar alekseybobkov avatar alxy avatar aurelien-roy avatar bennothommo avatar bmcouto avatar cggstudio avatar daftspunk avatar datune avatar felixinx avatar gergo85 avatar justin-lau avatar luketowers avatar mahony0 avatar mariavilaro avatar mjauvin avatar modmac avatar mplodowski avatar multiwebinc avatar munxar avatar niclasleonbock avatar nnmer avatar octoberapp avatar osmanzeki avatar samgeorges avatar samuell1 avatar tiipiik avatar tobias-kuendig avatar tomaszstrojny avatar vannut avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

translate-plugin's Issues

incorrect filname

The plugin does not get the correct filename on line 51 of Plugin.php when a name without extention is passed. the function substr_replace returns a wrong file name like .enintrotext for a content named introtext.htm

[Bug]With Model Translation records for all languages is not stored at time of creation

With model translation at time of creating record it not saved with all languages it only save default language content, at time of updating record it save records with all languages.

i have extends translation model with my plugin and when i create record with all languages it`s not save other languages record, i have also check with forum plugin i got same result while creating(not updating) channel with all languages its only save data for default language not for other languages.

it should be like when you create record with all languages its save content for all languages.

Clear cache not working properly

I'm editing my pages locally and then uploading them, but even doing clear cache and scan for new message, I get my strings for a partial repeated on the backend each time I re-upload the file... only happens for partials, possible bug?

Plugin installed, without class?

Hi,

I have installed the plugin, and working on an improvement for pages plugins (see issue #32). I have tried the RainLab.Translate.Behaviors.TranslatableModel behavior, but the class dosen't seem to exsist.

I have created a sample page, with this as code;

function onStart(){
    if (!class_exists('RainLab\Translate\Behaviors\TranslatableModel'))
         return;
    else{
        die('Class dosen\'t exsist!!');
    }    
}

And the result : Class dosen't exsist!!.

Seem weird.

Thanks

[Feature] Subdomain support

It would be nice if it could also support subdomains for languages.

For example:

it.octobercms.com
en.octobercms.com
de.octobercms.com

with the same logic for fallback

octobercms.com ( language = en )

Prefixing the language code to the URL doesn't work

I've created a page with translated content block and also translated strings. Translation works fine with default language switcher component, but it doesn't react on url prefix changing.

I've also intsalled MenuManager plugin by Ben Freke and Breadcrumbs by Jared Meyering.
October CMS build is 134 and Translate plugin version is 1.0.2.

Translating component's template

It is possible to translate strings in component's template file (components/xxx/default.htm) ?
Method what works in controller's htm files
<?= e(trans('cms::lang.component.no_records')) ?>
doesn't work in components.

It is excessively to add markup tag to each plugin which requires translation:
'translate' => function ($id, array $parameters = []) { return trans($id, $parameters); }

[feature] With model translation can we have editor ?

right now we have text field and textarea for model translation, but for content we don`t have editor which has ability to translate content.

if we has editor that has translate ability then it is very useful, it can be use for blog and static pages too.

Translate page's title

It's very important to translate page title, makes no sense to change the language and keep page title in another language.

AJAX error

Hi,

I have an error with the localePicker. When I choose a language, I get the following error;
AJAX handler 'onSwitchLocale' was not found.
ajax error

According to this thread, is a October related issue. But I just want to be sure, how can I resolve it?

Please note that mysite.com/{langcode}/ works.

Thanks

Translations when creating Models

Currently, translations do not work in Popups/Modals. Screenshot: https://www.dropbox.com/s/13lo069zldzkmqx/Screenshot%202014-08-23%2015.36.34.png?dl=0

The POST-data looks correct, it includes the translation strings. Also, the TranslatableModel::setTranslateAttribute() function is called accordingly. However, in the syncTranslatableAttributes()-method the $translateableAttributes array is empty (empty array).
My guess is, the model / model behaviour is re -instanciated somewhere in the application. It may be related to the way october saves related models, but I couldnt investigate this any further.
I could somehow verify my guess by specifying a default value on the array:

protected $translatableAttributes = ['test'];

In this case, it really contained this value in the syncTranslatableAttributes()-method.

Hope this helps a bit. to identify the error.

Messages won't translate

Hey,

using this plugin for a while now and decided to update it today, because why not, it's awesome.

Added a few more messages to be translated. They appear in the "Settings->Translate Messages" tab after scanning. Entered the translation, cleared the cache, but nothing happens. It's just using the default message, no matter what language I'm choosing (via localePicker or direct URL). Also tried to edit existing messages and they won't update as well. So I'm wondering where else they are actually cached?

Also cleared the browser cache several times just to be sure. It's weird because the setup worked in the past and all I did was updating the plugin and October. Content files are working fine for each of the languages. I'm running with October 238 right now.

Any Ideas on this?

Best,
Christian

Selecting language with URL prefix doesn't work on root route

With version 1.0.10, although the exception is no longer thrown as reported in #61, #62, and #64, the appropriate language is not being selected with URL prefix.

It seems to me as if no languages is being selected, not even the default language. It shows a 404 page, and when the locale picker is selected on this page an alert message pops up and display the value of X_OCTOBER_REDIRECT.

Update
The problem only occurs on the root route /

Add the ability to set the current language being translated in the backend

While translating custom models, each time you edit a model, the language for the translatable columns is set to the default language. Couldn't it be set to the current locale instead of the default locale?
Say for example the default is English and you are working on translating custom model to Spanish... it is annoying to set the little language selector inside the translatable column input each time you edit a model.
Is there a workaround for this?

Thanx

Let admins decide to store the language (locale) in the session

To address #42 and #57, I think it could be a good idea to allow the admin to decide whether or not the current locale should be stored in the session.

It could be file-based, with a key like sessionStored.

Either it's only code editable (config.php file), or it belong to some configuration page.

I would prefer a configuration page, which would also gather other parameters:

  • Store the lang in the cookies
  • Prevent content duplication:
    • Always redirect to URL with lang suffix
    • Always redirect to URL with lang subdomain prefix
    • ...
    • Nothing
  • Access the default lang via the canonical URL (without suffix/prefix)

[Bug] Fix grid scroll disabling other plugin events

To reproduce this issue go to october.dev/backend/rainlab/translate/messages

On this page it is not possible to scroll the left menu with the mouse scroll bar. (However, clicking the small bar and do the scrolling via drag & drop works)
I am experiencing this error in the current Chrome browser.

[ Feature ] Fallback configurability

It would be cool if the fallback could be set up as:

  1. Just keep the domain but use one specific language (eg. octobercms.com use EN as default)

  2. Redirect to one specific domain which is the default language (eg. octobercms.com -> en.octobercms.com )

Add PHP translation helpers

Short translation functions are currently restricted to Twig only, PHP needs an equivalent global function to assist with translations.

This may require the addition of a global init.php script for plugins.

Selecting language with URL prefix throws exception

On a clean dev-master October install, with just the translate plugin, when I try to select language with URL prefix an exception is thrown:

Call to undefined method Cms\Classes\Controller::getAfterFilters()
{project-root}/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php line 201

The locale-picker widget is however working properly.

Plugin doesn't work compatible with relation tables

We are developing a custom plugin and we have problems on relation tables.

We have Countries table and offices table. Countries has many offices related to country_id on offices table. We have defined all relations in models and in yaml files.

Every thing works fine on CRUD.

We are implemented translation plugin in to our pluing, Countires tables works great with translation table, but offices table saves blank fields for second language.

When I check the "rainlab_translate_attributes" table I can see recods for "Countries" model but there is no record for Offices Model.

The same thing occurs on "Menu Lists Plugin" here is the thread : https://octobercms.com/forum/post/menu-items-translation-doesnt-work-2

Incorrect locale while going from /locale/link to /link

I have found this issue:
I have 2 langs configured, Russian as default and English.
If you go for example to site.com/en/about , then go directly to site.com/about locale will not be changed to default. Thats because of this code in routes.php:

    $locale = Request::segment(1);
    if ($translator->setLocale($locale)) {
        Route::group(['prefix' => $locale], function() use ($locale) {
            Route::any('{slug}', 'Cms\Classes\Controller@run')->where('slug', '(.*)?');
        });
        Route::any($locale, 'Cms\Classes\Controller@run');
    }

setLocale will store locale in session, then later in Plugin.php locale will be loaded from session for translation. But going to site.com/about will not change locale in session since no locale specified in url and setLocale will fail.
This can be fixed with adding else:

    $locale = Request::segment(1);
    if ($translator->setLocale($locale)) {

        Route::group(['prefix' => $locale], function() use ($locale) {
            Route::any('{slug}', 'Cms\Classes\Controller@run')->where('slug', '(.*)?');
        });

        Route::any($locale, 'Cms\Classes\Controller@run');
    } else $translator->setLocale($translator->getDefaultLocale());

Fallback not translated Model properties to default locale

I have site with two languages, english (default) and german. I translated my Model class properties in backend from english to german and leave some of them blank. After I get record from database it has auto translated properties, but some of them are blank, because I did not fill them in backend.

It will be a good idea to fallback to default locale for those properties that are not translated. It is a better experience for user to see english value than an empty string.

Add repeater widget support

Currently the new repeater widget form fields cannot be translated. It would be nice to have this feature.

Cannot translate relation fields

  • Bug summary: When using the plugin on a relation form, translations are not saved to the database
  • Reproduce steps:
    1 Create a relation between two models that are translatable
    2 Create a config_relation on a controller
    3 Render the relation view
    4 Create a new relation record or update an existing one on the form, set the value in the different languages
  • Expected result: The translations are saved on the database
  • Actual result: No translations are saved

I think this is related to this issue #18

Best Practice for Translating editable content

The translate plugin works beautifully for editing phrases used within the "CMS" code of the web pages, and for data entered using models.

But I need to keep my "client-users" away from editing code in the CMS, obviously. And using the plugin as documented will result in all my default-language phrases being part of the "off limits" code in my CMS pages.

I have thought of a few solutions but I'm not sure what is best.

1: My CMS pages reference content blocks, and I make my client edit text files / content blocks, because I can create them all and add -langcode to the file names. So they can edit page-title.en.txt and page-title.fr.txt without having to modify {{ 'Page Title'|_ }}.

2: I create a "Placeholder" language, so that both English and French become translations. This would be the best client-user experience, but I'm anticipating a few problems on the front end with a default language that I don't really want anyone to ever see.

3: I create a model for each page, with attributes for each placeholder. This seems like it might work nicely, but it a lot of overhead for development and not very flexible as a CMS.

Any advice?

Cash clear crash

Hey ,
I am confronting a bug when tried to clear cache : this is the error message :
"Class 'System\Helpers\Cache' not found"

Regards

Translating State Model in User plugin.

I installed User plugin and Translate Plugin.
I used Translate Plugin to translate Countries and States in User plugin. There is no problem with translating Country Model, but something is wrong with translating State Model.

I added these lines in Country and State Models:

public $implement = ['RainLab.Translate.Behaviors.TranslatableModel'];
public $translatable = ['name'];

Next I went to Settings -> Locations in admin panel area. Inputs were changed dynamically by Translate Plugin. I translated Country record and so far everything is working fine. Next I tried to translate State, but translated state is not persisted to database. I checked $_POST variable and translation is sended. I debuged TranslatableModel.php and found that $translatableAttributes variable is empty in function syncTranslatableAttributes().

I quick fixed that by going through $_POST variable setting $translatableAttributes for RainLab\User\Models\State model in syncTranslatableAttributes() function.
That is very poor solution, but I have not found any other for this.

The problem persist everywhere where You use relationRender() function in backend view.

Sorry for my poor english. If you have questions I will try to help.

Exception when calling an URL in an other language

Hi,

I'm trying to set up the translate plugin, but I can't get it to work.
My site is initially in french (fr) and I want to have en english translation (en).

I think I set up everything fine, but when I call the URL localhost/en/, I have the following exception:

Call to undefined method Cms\Classes\Controller::getAfterFilters()

/.../october/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php line 202

I did a dump of $instance and it is of the class Cms\Classes\Controller (with does not have any getAfterFilters())
The normal request (without language prefix), uses a Cms\Classes\CmsController.

PS: I'm using the latest build (247) of octoberCMS and version 1.0.9 of the translate plugin (I also tried to disable all the other plugins, but it didn't solve my problem)

[question] This plugin is usable right now?

I update to the last build of OctoberCMS, and I start to test your plugin. But I don't know how to save/validate data using your amazing plugin.

I know is in development status, maybe is not working yet and maybe I'm very excited ...

Thanks.

[Feature] Adding plugin name to twig

Hi,

don't know if this is the correct name. I am using the translate plugin for me booking plugin, but I already have a lot of rows, so I figure that if I had some other plugins and some text to translate into the front side, there will be a lot of rows, and it would be very difficult to find witch row affect what.
So it would be really great to have something like:
{{ 'My text to translate'|tiipiik.booking|_ }}

Or maybe just have the ability to translate components with the lang files (lang/enlang.php)

This plugin could be the next big thing of OctoberCMS!!

I'm having some troubles configuring october cms backend in order to be used by my client who doesn't understand a line of code, and while I'm translating my site's content, I had what might be a great idea:

  • What if we could define translations by groups / pages? The plugin would have to identify which page that content belongs to, and then the client could just access translations to change it's content...

I'm having some troubles finding a way to give client the ability to change the content of a page without messing around with html and css, putting in risk the page interface, something like drupal where content is updated via input forms.
Maybe translation could accomplish this and be much more than a translations plugin, am I thinking correctly?

Untranslated strings found

  1. After installing this plugin, please click Settings in the back-end.
  2. The caption of 'Translation', 'Languages', 'Messages' and their descriptions remain English.

Sub-directory language files don't detect

The content directory became too congested due to the n number of extra lang files for each file I make so I figured it's a good idea to group them by putting them all in one folder. I changed the component code as {% component 'introduction' file='introduction/intro.htm' %} and then changed the intro.htm, intro.fr.htm, intro.de.htm to introduction/intro.htm, introduction/intro.fr.htm & introduction/intro.de.htm respectively. When I run the website however only the normal english version of it appears i.e. intro.htm and it throws a stack trace error for other languages. When I remove the introduction/ from the other languages it works but then I'm not able to declutter and organise it better!

Update: Something else was wrong, the plugin works even on sub directory levels once I force updated the backend.

Page translation

Is it possible to translate page.htm files? Like page.fr.htm or put pages in subdirectory like /fr/page.htm?

I've tried to put translated pages in subdirectory but current route rules

Route::group(['prefix' => $locale], function() use ($locale) {
Route::any('{slug}', 'Cms\Classes\Controller@run')->where('slug', '(.*)?');
});
Route::any($locale, 'Cms\Classes\Controller@run');

prevents this way of routing. I get 404 on all site.com/fr/page requests.

Plural forms

First of all, i must say that u made a great work with this plugin!

It's all done like it should be but i'm missing settings for plural forms (i saw for English, but English have just 2). This is what i miss in all major CMS systems, this could be one of advantages of October.

I am from Slovenia and our language is very complicated, we have 4 plural forms as you can see it on this link under Slovenian (SL) http://localization-guide.readthedocs.org/en/latest/l10n/pluralforms.html.

Is there any way to implement this in this great plugin?

I already made such a plugin, but in javascript for node.js.

Implementation is very simple. This way you can cover all languages around the world. Language file need settings for:

  • plural form function that calculates plural form index, n is number that user provide. In our language is:

    plural_form_index = (n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0);

  • number of plural forms of Language

    numer_of_plural_forms = 4; <- this value you need just in case when u click 'Scan for translations' trough templates, that keys are automatically generated (e.g. 'posts', 'posts.1', 'posts.2', 'posts.3').

So translation for "posts" can be saved like:

Plural form Translation key or text Translation of key in Slovenian language
form 0 'posts' ':count prispevkov' (when plural_form_index is 0)
form 1 'posts.1' ':count prispevek' (when plural_form_index is 1)
form 2 'posts.2' ':count prispevka' (when plural_form_index is 2)
form 3 'posts.3' ':count prispevki' (when plural_form_index is 3)

So when translation happen, you just look for same key + dot + plural_form_index on the end, if it doesn't exist, it returns default form 0.

For example:

{{ 'posts'|__(2) }}
This means you put 2 in plural form function which outputs plural_form_index = 2, so you look for key 'posts.2' and translate it, if it doesn't exists you try to translate default key 'posts' (default plural form 0).

You can still preserve syntax like this
{{ 'posts|posts.1|posts.2|posts.3'|__(2) }}
, but in this case you will need to know in advance which languages you will use, and how many plural forms they need. So this sounds a little complicated to me.

If you have any questions, do not hesitate.

Thanks for great work!

vizo

[BOUNTY] Translating page's url & implement translatable indexes

A bounty has been placed on this issue

Scope definition

  • CMS Page URLs should be translatable (see below for technical description)
  • Static Page URLs should be translatable (see #156)
  • Models should support index definitions and lookup mechanism

It would be nice to be able to translate the path when creating a new page.

Taken from #112:

Basically, if I have three languages, for instance "en", "fr", "de", and an about page,
I currently can access :

/en/about
/fr/about
/de/about
For SEO purposes, I would prefer to access (as the same route) :

/en/about
/fr/a-propos
/de/uber-uns

Add theme translations to version control

Is there a way to add translations for a front-end theme to version control, without having to add them to the database? This would allow for a theme to be translated while developing and having the translations available at the moment that the site is put live.

Default root (/) language

In documentation is written:

I think, if you have multilingual site, it is better that you always redirected to /language when you come to root. Joomla have the same option. Why?

  • people often don't look at url, they just make bookmark, share, etc., so if you change default language later, content could be gone on same url, which is very bad.
  • for search engines content is duplicated on two urls: / and /language, which is also bad

Is it possible to make this as an option, that you are always redirected?

So when user come to root, it checks:

  1. if user have language in session, redirect to user's language
  2. if browser sends language in request header, redirect to browser's language
  3. redirect to default language

Thanks in advance,
vizo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.