EddyVerbruggen / nativescript-localize

Internationalization plugin for NativeScript using native capabilities of each platform
MIT License
79 stars 31 forks source link

Does not localize #61

Closed santteegt closed 5 years ago

santteegt commented 5 years ago

Hi,

I'm trying to use your library on an app but the string is not being localized.

image

I'm importing the NativeScriptCommonModule on a shared module:

import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { NativeScriptLocalizeModule } from "nativescript-localize/angular";

@NgModule({
    imports: [ 
        CommonModule,
        NativeScriptLocalizeModule
    ],
    declarations: [
    ],
    exports: [
        CommonModule,
        FormsModule,
        NativeScriptLocalizeModule
    ]
})
export class SharedModule { }

Then on the component's module I'm importing this SharedModule:

import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
import { NativeScriptCommonModule } from "nativescript-angular/common";

import { LoginRoutingModule } from "./login-routing.module";
import { LoginComponent } from "./login.component";

import { SharedModule } from "../shared/shared.module";

@NgModule({
    imports: [
        NativeScriptCommonModule,
        LoginRoutingModule,
        SharedModule
    ],
    declarations: [
        LoginComponent
    ],
    schemas: [
        NO_ERRORS_SCHEMA
    ]
})
export class LoginModule { }

And, on the component HTML template, I'm using the L pipe as follows:

...
<Label class="t-30 company-name" text="{{ 'app.name' | L }}"></Label>
...

My i18n directory structure is:

app --i18n ----de.js ----en.default.js

The en.default.js contains:

module.exports = {
    "app.name": "My app",
    "company.name": "My company"
};

Dependencies version

What could be the problem? Does the app.name should have the specific name for the nativescript app project I created?

ibenzyk commented 5 years ago

@santteegt I've faced same problem try to move you i18n folder one level up

src --app --i18n ----de.js ----en.default.js

and it works for me

santteegt commented 5 years ago

It worked! Thanks @ibenzyk

caiusCitiriga commented 5 years ago

@ibenzyk thanks! It worked for me too. But shouldn't this thing be kinda said in the README @lfabreges?

vasudevpareek07 commented 4 years ago

@EddyVerbruggen @breningham , I am not able to change the language with in the app.

I am using Nativescript with angular.

I created i18n directory under src folder, when i try to change the language, based on the documentation https://market.nativescript.org/plugins/nativescript-localize here for angular,

es.default.json: { "Hello": "Hello", "app_name": "My app", "title_activity_kimera": "My app", }

hi.json: { "Hello": "नमस्कार", "app_name": "My app", "title_activity_kimera": "My app" }

Following things i imported in angular component:

import { android as _android } from '@nativescript/core/application'; import { overrideLocale } from 'nativescript-localize/localize'; import { isAndroid } from 'tns-core-modules/platform';

function which i call when user tries to change the language:

switchLanguage(selectedLang){ L.localize.overrideLocale(selectedLang); if (isAndroid) { _android.foregroundActivity.finish(); } }

Here in the function, it sasy 'L' is not defined. Any help would be appreciated. Thanks.