-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
106 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"curly": true, | ||
"eqeqeq": true, | ||
"immed": true, | ||
"latedef": true, | ||
"newcap": true, | ||
"noarg": true, | ||
"sub": true, | ||
"undef": true, | ||
"boss": true, | ||
"eqnull": true, | ||
"node": true, | ||
"white": true, | ||
"predef": [ | ||
"angular", | ||
"describe", | ||
"it", | ||
"before", | ||
"beforeEach", | ||
"after", | ||
"afterEach" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
angular.module('gettext').directive('translate', function (gettextCatalog, $interpolate, $parse) { | ||
return { | ||
transclude: 'element', | ||
priority: 900, | ||
compile: function (element, attrs, transclude) { | ||
return function ($scope, $element) { | ||
// Validate attributes | ||
var err = function (missing, found) { | ||
throw new Error("You should add a " + missing + " attribute whenever you add a " + found + " attribute."); | ||
}; | ||
if (attrs.translatePlural && !attrs.translateN) { err('translate-n', 'translate-plural'); } | ||
if (attrs.translateN && !attrs.translatePlural) { err('translate-plural', 'translate-n'); } | ||
|
||
var countFn = $parse(attrs.translateN); | ||
|
||
transclude($scope, function (clone) { | ||
var input = clone.html(); | ||
clone.removeAttr('translate'); | ||
$element.replaceWith(clone); | ||
|
||
return $scope.$watch(function () { | ||
var prev = clone.html(); | ||
|
||
// Fetch correct translated string. | ||
var translated; | ||
if (attrs.translatePlural) { | ||
translated = gettextCatalog.getPlural(countFn($scope), input, attrs.translatePlural); | ||
} else { | ||
translated = gettextCatalog.getString(input); | ||
} | ||
|
||
// Interpolate with scope. | ||
var interpolated = $interpolate(translated)($scope); | ||
if (prev === interpolated) { | ||
return; // Skip DOM change. | ||
} | ||
|
||
return clone.html(interpolated); | ||
}); | ||
}); | ||
}; | ||
} | ||
}; | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
angular.module('gettext').filter('translate', function (gettextCatalog, $interpolate, $parse) { | ||
return function (input) { | ||
return gettextCatalog.getString(input); | ||
}; | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
angular.module('gettext', []); | ||
|
||
angular.module('gettext').factory('gettext', function () { | ||
/* | ||
* Does nothing, simply returns the input string. | ||
* | ||
* This function serves as a marker for `grunt-angular-gettext` to know that | ||
* this string should be extracted for translations. | ||
*/ | ||
return function (str) { | ||
return str; | ||
}; | ||
}); |
33557ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function returns an input string rather then translated version of it. According to http://angular-gettext.rocketeer.be/dev-guide/annotate-js/ it marks text for translation. It would make sense though if it returned translated version.
For my own needs, I made the following fix to that function:
angular.module("gettext").factory("gettext",[
'gettextCatalog',
'$interpolate',
'$parse',
function(gettextCatalog, $interpolate, $parse){
return function(str) {
return gettextCatalog.getString(a);
}
}]);
33557ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is intentional. You don't want your strings translated at that point, otherwise they won't get retranslated whenever the language changes.