Sylius: Translations for the theme

Created on 18 Jun 2016  Â·  21Comments  Â·  Source: Sylius/Sylius

I have a theme in which I have a few overrides of a few bundles like SyliusWebBundle, SyliusShippingBundle and SyliusCoreBundle (just the translation files). I wanted to have the translation for 'sylius.form.channel.taxons' and 'sylius.form.locale.select' which is being used in administration section's 'Add Channel'. I put the files into SyliusCoreBundle/translations and base translations under the theme. I even tried to override the 'sylius.meta.frontend_title' in the SyliusWebBundle but even that does not work.
My feeling is, none of the translations in the theme is working (may be for me). Is there some settings that I might be missing?

Help Wanted

Most helpful comment

@Ghosst42 @pamil @pjedrzejewski at last I found out how to make the translations to work.
My locale is en_US. So my expectations were, messages.en.yml will serve as the translation file. But unfortunately, the locale does not fallback to en even though it is defined in the config file. But if you particularly define the locale in the translation file, for example messages.en_US.yml it works. Until this is fixed (I am not sure if this needs a fix), one can use the locale specific to his/her choice. But I still have some problem with the translation files for the backend templates. Once I can find something more, I will add it here.

All 21 comments

Did you add ThemeBundle after FrameworkBundle in the Kernel?

@pjedrzejewski I am using the latest version and did not add any of this bundles manually. But from the kernel settings at SyliusCoreBundle/Application/Kernel.php it seems that the ThemeBundle is the last one and is loaded after the Framework bundle. From the 'php app/console config:dump-reference' I have verified that that the 'sylius_theme' is loaded long after the 'framework' (there is no other bundle such as sylius_framework though).
Just to mention, the overriding of the templates are working as expected.

Have you cleared the cache after adding translation files?

@pamil I have cleared the cache from console, even deleted the cached files manually. Any template change reacts only after clearing the cache but that does not have any effect on the translation. Some how translation is not at all working for me. Neither can I even change the title of my page by changing the content in the template file. I upgraded of shifted from Sylius 0.16 to Sylius 0.19 for my project. In 0.16 I was overriding the WebBundle with my own bundle and the translation worked fine. I upgraded with a new installation of version 0.19 and modifying and adding bundles and themes accordingly, so it is nearly a new work and not just changing or modifying the files in the old existing project.

@pjedrzejewski @pamil are the translation in the themes working fine at your place? Did you have time to test it. I am very curious if it is working for others (and / or with a fresh install) and not working only for me.

We've got some end-to-end tests in ThemeBundle, so the translations should be working. If you could reproduce this bug on Sylius-Standard / Symfony-Standard and share it, I will definitely have a look and try to debug this issue.

I have tried all the way possible. Even with a fresh new installation. But still the problem exists. Are you sure in the loading order, the translations of the theme folder is loaded before the bundle? Or at least even loading the translation from the theme folder? I have tried with some new variable which is not present in the bundle.

Yeah, I am quite sure the theme translations are loaded at the end, because every loaded translation files overrides the previous one. I cannot help you without more details - I would need sylius_theme configuration (app/console debug:config sylius_theme), structure and location of your theme (tree app/themes/your-theme) etc.

Hi @pamil , thanks for giving so much time for solving my problem. I am posting all my settings and folder structure.

My theme configuration at app/config/config.yml is:

sylius_theme:
    sources:
        filesystem: ~

My debug:config sylius_theme gives as:

Current configuration for extension with alias "sylius_theme"
=============================================================

sylius_theme:
    context: sylius.theme.context.channel_based
    sources:
        filesystem:
            enabled: true
            filename: composer.json
            directories:
                - '%kernel.root_dir%/themes'
        test:
            enabled: false

And here is my file structure for the themes:
screen shot 2016-06-21 at 22 43 37

Now, I want to override the translation in the SyliusWebBundle or want to add some new values, but this does not happen. At least I can't make it work. Neither the existing values change nor the new values shows up.

I have also have tried clearing up the cache from app/console php app/console cache:clear and have even deleted the cache files manually rm -rf app/cache/*. But nothing gives me anything as expected.

Am I doing something wrong? I am stuck here for so long. Else I have to hardcode the values. But I really want Sylius to be smooth because this this the main reason for me choosing Sylius over Thalia.

Hmm, everything looks fine. The only possibility is that the theme is not enabled. Have you set bridal theme in the channel you're using? That can be done in old administration panel while editing a channel or the hard way by editing sylius_channel.theme_name column in database.

Hi!

I have the same problem. I can override the views but i can't the translations.
app/themes/my_theme_name/bundle_name/translations not working. So i have to use the app/resources/bundle_name/translations folder.

Cache cleared.
Cache hard deleted.
Theme enabled on channel.

sylius_theme:
    sources:
        filesystem: ~
Current configuration for extension with alias "sylius_theme"
=============================================================

sylius_theme:
    context: sylius.theme.context.channel_based
    sources:
        filesystem:
            enabled: true
            filename: composer.json
            directories:
                - '%kernel.root_dir%/themes'
        test:
            enabled: false

Version: Sylius 0.18.0-dev

Everything is present in the data base as well as my configuration. I am putting here the screenshot from my channels configuration.
screen shot 2016-06-22 at 14 58 32

@pamil any update on the issue? For your information, I am also giving the screenshots of my translation in the _profiler:

screen shot 2016-06-25 at 04 12 16

@pjedrzejewski any comments on this situation?

@Ghosst42 @pamil @pjedrzejewski at last I found out how to make the translations to work.
My locale is en_US. So my expectations were, messages.en.yml will serve as the translation file. But unfortunately, the locale does not fallback to en even though it is defined in the config file. But if you particularly define the locale in the translation file, for example messages.en_US.yml it works. Until this is fixed (I am not sure if this needs a fix), one can use the locale specific to his/her choice. But I still have some problem with the translation files for the backend templates. Once I can find something more, I will add it here.

Thanks a lot @stiffroy for debugging this! Seems like translation fallbacks do not work for themes. We will have a look as soon as possible. /cc @pamil

@pjedrzejewski Most welcome... I did not get much time to work on it. I am thinking of setting some translations in order. As soon as I do that, I will create a pull request.

@stiffroy thanks! It is definitely this issue.

The theme translator makes locales by concatenating locale with theme name. Let's say your locale is en_US and theme name is example/theme. Then the following locales are used:

  • en_US_example-theme
  • en_US
  • en

However, theme aware locale of messages.en.yml in example/theme is en_example-theme.

The way we need to make this work, is that it should load the following locales:

  • en_US_example-theme
  • en_example-theme
  • en_US
  • en

All locales with theme suffix and then all locales without it. Unfortunately, I can't find a clean way to implement it now, as the present one is quite hacky :)

@pamil but when I checked for the locale loading, the last one to override was en_example-theme but unfortunately the themes are not working right now (after the last update of sylius yesterday). My lodating order for the locale is as:

"en_US"
"af"
"ar"
"az"
"bg"
"ca"
"cs"
"cy"
"da"
"de"
"el"
"en"
"es"
"et"
"eu"
"fa"
"fi"
"fr"
"gl"
"he"
"hr"
"hu"
"hy"
"id"
"it"
"ja"
"lb"
"lt"
"mn"
"nl"
"nn"
"no"
"pl"
"pt"
"pt_BR"
"ro"
"ru"
"sk"
"sl"
"sq"
"sr_Cyrl"
"sr_Latn"
"sv"
"th"
"tr"
"uk"
"vi"
"zh_CN"
"zh_TW"
"lv"
"pt_PT"
"ua"
"be"
"de_CH"
"ko"
"mk"
"ms"
"sr"
"sr_CS"

But i think this can be done by changing the order of the loading of locale in Translator::warmUp(). I will try that in the evening and as soon as I get something, I will let you know.

In the meanwhile, can you please check why did the themes stop working completely after the update and clearing the cache? In the admin settings (database), it is showing the theme is still assigned and from the console, the themes are also present in the list. But theme is not working or even showing up in the debug toolbar.

Okay, I'll see what I can do with broken themes.

Hi,
First thanks to Sylius team for this great tool.
I have the same problem with Sylius 1.2.5. Tried to clear cache, delete cache manually, fallback translation … Nothing work :(

I noticed that in the debug bar, the local is fr_FR@app-theme-name so I tried to replace fr by this but it does'nt work.

Tried to put translations in app/themes/MyTheme/translations, app/themes/MyTheme/AppBundle/translations and app/themes/MyTheme/SyliusShopBundle/translations but doesn't work also ...

Current configuration for extension with alias "sylius_theme"
=============================================================

sylius_theme:
    context: sylius.theme.context.channel_based
    sources:
        filesystem:
            enabled: true
            filename: composer.json
            scan_depth: null
            directories:
                - 'C:\wamp64\www\sylius/app/themes'
        test:
            enabled: false
    assets:
        enabled: true
    templating:
        enabled: true
    translations:
        enabled: true

Never mind : I find why ! It's because I use Windows and I have to replace translations/ by translations\ in :

https://github.com/Sylius/Sylius/blob/e42ee5ac96b0817485a1b1741eda8a0cfaeab27e/src/Sylius/Bundle/ThemeBundle/Translation/Finder/TranslationFilesFinder.php#L79

So nice bug 🤣 I will do a PR

Was this page helpful?
0 / 5 - 0 ratings