Search code examples
asp.net-mvcangularjsrazorgettextpo

Angular-gettext extract annotations from .cshtml file


I'm using Angular-gettext to extract strings from .html and .js files for multi-language translation using Gruntfile.js:

  grunt.initConfig({
    nggettext_extract: {
      pot: {
        files: {
          'po/template.pot': ['**/*.html', '**/*.cshtml', '**/controller.caseload.js']
        }
      },
    }

But when I try to pull from a .cshtml file, it is not being extracted.

I need to extract from my Header.cshtml file because I am using it as my Layout for my angular app. The layout basically displays a header bar at the top of every page that contains user information (Profile, Preferences, Logout, etc.).

When I try to add a line like <div translate>Preferences<div> to my Header.cshtml file, it doesn't extract into my .pot file. But if I add that same line to my index.html file, it extracts correctly and I am then able to define a translation for it.

Is there a good way to do this with angular-gettext for .cshtml files?


Solution

  • Try to add this code to your option section.

                options: {
                    extensions: {
                        htm: 'html',
                        html: 'html',
                        php: 'html',
                        phtml: 'html',
                        tml: 'html',
                        js: 'js',
                        cshtml: 'html'
                    }
    

    Maybe it's trying to parse your template as a Javascript by default.