Feature #32607

Export localized strings for JS consumption

Added by Karsten Dambekalns almost 10 years ago. Updated over 8 years ago.

Status:
Needs Feedback
Priority:
Should have
Category:
I18n
Target version:
-
Start date:
2011-12-15
Due date:
% Done:

0%

Estimated time:
PHP Version:
Has patch:
No
Complexity:

Description

We need a way to export all messages of a locale for use in JS on the client side.


Related issues

Related to TYPO3 Flow Base Distribution - Story #42407: Asset ManagementNew2012-10-26

Actions
#1

Updated by Adrian Föder almost 10 years ago

I'd even like to see an option to flag specific messages for export.. We surely needn't every all available messages pushed out to the client.

Also there's the need to take care about different js-framework's localization approaches. In MooTools for example, it's

Locale.define('en-US', 'Date' /* Date is the entitiy to describe, could also be 'Vendor\MyPackage\Domain\Model\Thing' */, {

    months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
    days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
    dateOrder: ['month', 'date', 'year', '/'],
    AM: "AM",
    PM: "PM",
    //members can be functions; these will be executed and passed any arguments with .get(member[,args])
    ordinal: function(dayOfMonth){
        return (dayOfMonth > 3 && dayOfMonth < 21) ? 'th' : ['th', 'st', 'nd', 'rd', 'th'][Math.min(dayOfMonth % 10, 4)];
    },
    lessThanMinuteAgo: 'less than a minute ago'

});

I'm open for discussion :)

#2

Updated by Karsten Dambekalns over 9 years ago

  • Status changed from New to Needs Feedback
  • Assignee set to Karsten Dambekalns
  • Target version set to 1.1

It would be nice to have this in 1.1 - but I need input from the JS folks on this!

#3

Updated by Bastian Waidelich over 9 years ago

Maybe this could be achieved with a ViewHelper:

<script>
var myLabels = {f:xliffToJson(source: 'SomeLabelsCatalog', locale: 'de_DE')};
</script>

(with cooler naming)

#4

Updated by Alexander Berl over 9 years ago

I like the viewhelper idea. Options that such a viewhelper should have:
- select locale (obviously), default should be current session locale
- select package where translations get picked from (optimally it would also be possible to get translations from all packages)
- get a list of translations that start with a specific identifier prefix (e.g. "foo.bar.baz.*" or "date.month.long.*")
- result array should be possible to be associative (with identifier as key) or indexed (default behaviour?)

#5

Updated by Karsten Dambekalns over 9 years ago

  • Target version changed from 1.1 to 2.0 beta 1
#6

Updated by Francois Suter almost 9 years ago

I agree that this would be very useful. Filtering the messages would be a nice option.

A reference could be the JS localization found in TYPO3 CMS (typo3/sysext/lang/res/js/be/typo3lang.js). It even handles plurals.

The main question is where to generate such a file. A view helper makes sense IMO.

#7

Updated by Adrian Föder almost 9 years ago

I think that should go hand-in-hand with #42407 which I just added as a relation to this issue.

#8

Updated by Francois Suter almost 9 years ago

If this can be of any use, here's a quick and dirty solution I threw together for a project: https://gist.github.com/4065082

#9

Updated by Karsten Dambekalns almost 9 years ago

  • Target version changed from 2.0 beta 1 to 2.1
#10

Updated by Robert Lemke over 8 years ago

  • Target version deleted (2.1)

Also available in: Atom PDF