Handling long blocks of text to be translated in i18N

In my case, I put the end result in the ‘dist’ folder along with other static assets (like images and svgs)

process-json.ts

import * as gulp from 'gulp';
import * as project from '../aurelia.json';
import * as json5 from 'gulp-json5-to-json';

export default function processJson() {
  // Locales processor
  return gulp
    .src(project.jsonProcessor.source, { since: gulp.lastRun(processJson) })
    .pipe(json5())
    .pipe(gulp.dest(project.jsonProcessor.output));
}

aurelia.json jsonProcessor section

  "jsonProcessor": {
    "source": [
      "src/i18n/**/*.json5"
    ],
    "output": "dist/i18n"
  },
2 Likes

I fear you’d have to create a minimal repro on GitHub or somewhere so I can take a look at. I’ve just created a fresh new project and it worked as described so I guess there is just one more little gotcha hidden somewhere.

1 Like

I’ve just given you full access to the app.

main.ts is setup for the old working json. Just uncomment the relevant bits

1 Like

thx @jeremyholt. I’ve created a new repo showing how that is supposed to work. https://github.com/zewa666/aurelia-i18n-with-yml

From looking at your application I can’t really figure out what went wrong, since if you inspect my sample I had the translations done as you have. What is different though is how you host those files. In the CLI example of mine I’ve just pulled out the locales folder into root and accessing them from there. But in your C# project that might be different. I saw the copy task in your aurelia.json configuration so perhaps your backend isn’t serving the files properly.

Since you have debug: true do you see any weird outputs in your console?

EDIT: can’t run your sample since I’m on Mac or alternatively Linux at home :frowning:

2 Likes

@zewa666 Thanks so much for taking the time to look at this for me. I’ve compared line by line your app with mine. I went through build.ts, transpile.ts, aurelia.json and changed the tiny differences so that both projects are truly identical.

I can see that the translation files are copied correctly to wwwroot/locales.

I think I’ve discovered the problem - just need to find out how to resolve it.

I’m 99% sure that the C# server is not serving up yml files

If I click on translation.json - the page responds with the json file, but if I click on translation.yml I get 'page not found`.

I’m sure this is the problem.

I’ll report back when I’ve learned how to serve yml pages.

Again, many thanks for your help
Jeremy

1 Like

OK - I needed to add a content provider for yml.

The code needed in Startup is:

This saga should probably be added to the documentation somewhere.

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            Globalization.Configure(app);
            
            var provider = new FileExtensionContentTypeProvider();
            provider.Mappings[".yml"] = "text/plain";
            
// this is the bit that adds the yml files
            app.UseStaticFiles(new StaticFileOptions
            {
                FileProvider = new PhysicalFileProvider(
                    Path.Combine(Directory.GetCurrentDirectory(),"wwwroot","locales")),
                RequestPath = "/locales",
                ContentTypeProvider = provider
            });
            
            app.UseFileServer(new FileServerOptions {EnableDefaultFiles = true, EnableDirectoryBrowsing = false});
            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();
            app.UseHttpsRedirection();
            SwaggerInitialize.Configure(app);

            app.UseEndpoints(endpoints => endpoints.MapDefaultControllerRoute().RequireAuthorization());

            Log.Logger.Information("Successfully ran Startup.Configure()");
        }

Again - thanks so much for everyone’s help - I would never have got here on my own!

3 Likes

Just out of interest sake, the >- symbol appears to be a legitimate multiline key

The app I’m using to help with the translations https://github.com/gilmarsquinelato/i18n-manager inserts this symbol into the yaml, and it seems to be working fine.

2 Likes

Last question - I promise!

I use Google Translate for translating French and Portuguese. It does a pretty good job, and I’m fluent enough in both languages to spot any silly errors.

However, I also need to translate into Vietnamese. My friends in Vietnam tell me that Google is atrocious in doing the translation.

Does anyone have any experience of translating into Vietnamese, or could suggest a cheap (preferably free) service that can do the translations?

Mind you, now that I’ve moved over to yaml , the files are much easier to hand over to a non-programmer and ask him to do the translation.

1 Like

First of all, glad that you got it working. Was a hard ride but you’ve eventually made it. Congratz :slight_smile:

Looking at your FileExtTypeProvider, I’d suggest to switch the mime type to the correct one for yml application/x-yaml, which resembles application/json quite well.

I’m defintely new to yaml myself so good to know that >- is possible as well.

Talking about translations, the guys behind i18next have a service called Locize. On their services page they’re listing a few partners which might be a good start for your search.

1 Like

Changed the file content provider as you suggested. It’s still working :slight_smile:

Checked out Locize - very interesting - I’ll give it a go when I’ve finished the app.

Again - many, many thanks for your help
Jeremy

2 Likes

The best thanks is to spread the word about Aurelia :wink:

1 Like

I do have experience of translating into Vietnamese but you don’t want to hire me (it’s not cheap).
Unfortunately there are no reliable automated solutions for English - Vietnamese translation yet; I have tried Amazon, Microsoft, Google, Babel, etc.
Your best bet would be a professional translation service, such as https://translated.com/

2 Likes