angular-gettext does not pick the strings from .PO files

487 views Asked by At

I have installed everything according to documentation. Some of the things are working as per the documentation. Is there something like Django translation which automatically replaces the translation for specific language if you select those lang ?

Index.html

<!DOCTYPE HTML>
<html>
{% load static %}
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js"></script>
<script src="{% static 'first.js'%}"></script>
<script src="{% static '/angular-gettext/dist/angular-gettext.js'%}"></script>

<script type="text/javascript" >
    angular.module('first').run(function (gettextCatalog) {
    gettextCatalog.setCurrentLanguage('fr');
    gettextCatalog.debug = true;
    gettextCatalog.setStrings('fr', {
    "Hello!":"Bonjour !"});

});

</script>

</head>
<body>
<div ng-app="first">
    <translate>Hello!</translate> Sagar
    <h1 translate>Hello!</h1>

</div>

</body>
</html>

PO file

msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"X-Generator: Poedit 2.2.3\n"
"Last-Translator: \n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"Language: fr\n"

#: ui/templates/admin/firsttranslate/index.html:24
#: ui/templates/admin/firsttranslate/index.html:26
msgid "Hello!"
msgstr "Halo !"

When I run my code It searches for Hello and Replaces with Bonjour But I want it to be replace automatically as Django does Thanks in advance.

1

There are 1 answers

0
Sagar On BEST ANSWER

I forgot mentioned the path of file in Gruntfile.js

'use strict';

module.exports = function (grunt) {
grunt.initConfig({
    nggettext_extract: {
        pot: {
            files: {
                'po/template.pot': ['ui/templates/admin/firsttranslate/*.html', 'js/first.js']
            }
        },
    },

    nggettext_compile: {
        all: {
            files: {
                'js/translations.js': ['fr/LC_MESSAGES/djangojs.po']
            }
        },
    },
});

grunt.loadNpmTasks('grunt-angular-gettext');

grunt.registerTask('default', ['nggettext_extract', 'nggettext_compile']);
};