Feature #32607

Export localized strings for JS consumption

Added by Karsten Dambekalns over 3 years ago. Updated about 2 years ago.

Status:Needs Feedback Start date:2011-12-15
Priority:Should have Due date:
Assigned To:Karsten Dambekalns % Done:

0%

Category:I18n
Target version:-
PHP Version: Complexity:
Has patch:No

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 Management New 2012-10-26

History

#1 Updated by Adrian Föder over 3 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

 1Locale.define('en-US', 'Date' /* Date is the entitiy to describe, could also be 'Vendor\MyPackage\Domain\Model\Thing' */, {
 2
 3    months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
 4    days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
 5    dateOrder: ['month', 'date', 'year', '/'],
 6    AM: "AM",
 7    PM: "PM",
 8    //members can be functions; these will be executed and passed any arguments with .get(member[,args])
 9    ordinal: function(dayOfMonth){
10        return (dayOfMonth > 3 && dayOfMonth < 21) ? 'th' : ['th', 'st', 'nd', 'rd', 'th'][Math.min(dayOfMonth % 10, 4)];
11    },
12    lessThanMinuteAgo: 'less than a minute ago'
13
14});

I'm open for discussion :)

#2 Updated by Karsten Dambekalns over 3 years ago

  • Status changed from New to Needs Feedback
  • Assigned To 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 3 years ago

Maybe this could be achieved with a ViewHelper:

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

(with cooler naming)

#4 Updated by Alexander Berl over 3 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 about 3 years ago

  • Target version changed from 1.1 to 2.0 beta 1

#6 Updated by Francois Suter over 2 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 over 2 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 over 2 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 over 2 years ago

  • Target version changed from 2.0 beta 1 to 2.1

#10 Updated by Robert Lemke about 2 years ago

  • Target version deleted (2.1)

Also available in: Atom PDF