question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with loading translations from nested folders

See original GitHub issue

Hi,

Using Laravel 7.x and the v1.0.2 version of this package.

I’m having an issue when generating translations in nested folders.

Example:

Inside the lang/en folder I have a folder called admin and here I have a file called master.php.

When I try to get a key from that file using $t('admin.content.title') it will return the string 'admin.content.title' instead of its actual content. But if i put that same file in the root of the lang/en folder it will return the value correctly. I already tried some variants but so far i couldn’t figure out how to go inside folders.

I tried both configs as stated in the docs:

  • First config

Mix:

mix.extend('translations', new class {
    webpackRules() {
        return {
            test: path.resolve(__dirname, 'resources/js/lang/index.js'),
            loader: '@kirschbaum-development/laravel-translations-loader/php?parameters={$1}'
        }
    }
});

mix.translations();

app.js:

import languageBundle from 'resources/lang/index.js';
import VueI18n from 'vue-i18n';
Vue.use(VueI18n);

const i18n = new VueI18n({
    locale: window.Locale,
    messages: languageBundle,
})
  • Second config

app.js:

import languageBundle from '@kirschbaum-development/laravel-translations-loader/php!@kirschbaum-development/laravel-translations-loader';
import VueI18n from 'vue-i18n';
Vue.use(VueI18n);

const i18n = new VueI18n({
    locale: window.Locale,
    messages: languageBundle,
})

Both don’t work. More, the first config doesnt even create the content inside the index.js file that i created for the effect.

Could use some help. Maybe i’m doing something wrong, most likely 😛

Thanks

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
luisdalmolincommented, Oct 24, 2020

Great, that’s good to hear it’s working now. I’ll close this issue.

1reaction
luisdalmolincommented, Oct 24, 2020

@Morinohtar Yeah, to load from nested folders you will have to be on the latest version. Also, the index.js file you’ve created is not going to receive any content, it only serves as a “fake” to tell webpack where your language files are located, basically.

Any change you can post your lang file in here? It seems that some content in there is failing to parse. By any chance, you have any PHP code in the language file? Can you post the content here?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Loading Multiple file from a directory. · Issue #199 - GitHub
I have implemented one for loading multiple files. ` /**/ import {TranslateLoader} from 'ng2-translate/ng2-translate'; import {Http, Response} ...
Read more >
react-i18next with multiple translation-files - Stack Overflow
Now I want update this so that i18next would take the translation files placed in the different component-folders and their children-folders.
Read more >
Add or Load Translations - i18next documentation
There are a few options to load translations to your application instrumented by i18next. The most common approach to this adding a so...
Read more >
Lazy Load and Encapsulate i18n Files in Angular with Transloco
Inline Loaders allow us to encapsulate our translation files and put them under the feature's folder, by providing a specific loader to the ......
Read more >
Translate your React Applications with i18next
Translating your website to different languages is a great way to expand your audience and make your content more accessible to people.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found