Code Monkey home page Code Monkey logo

Comments (6)

tj avatar tj commented on August 14, 2024

yeah tough call.. ideally we try to stay away from english etc but obviously that's not alway possible haha. I guess each component just needs to expose maybe an object containing the strings uses so they can be swapped, or we can try to get everyone using something like https://github.com/component/t, tough call. As long as they can easily be replaced then the application can handle the rest

from component.

juliangruber avatar juliangruber commented on August 14, 2024

staying library-agnostic would be great. we atm use gettext for easy collaboration with translation bureaus and sticking to an approved standard.

what i do now:

  • leave strings out of the template
  • pass a translation fn to the component
  • fill in text through dom traversal and calls to that fn

this works with gettext and t. you alao get the benefit of having all translations take place in one code block.

is dom traversal the preferred way of doing this anyway, or will sth like mustache be integrated?

from component.

juliangruber avatar juliangruber commented on August 14, 2024
var $ = require('jquery');
var clazz = require('clazz');
var ee = require('events').EventEmitter;
var bind = require('bind');

function Card(pattern, t) {
  clazz.base(this);
  if (!t) t = function(s) { return s; };

  var dom = this.dom = $(require('./template'));

  dom.find('a').click(function(e) { e.preventDefault(); });

  dom.find('.patternchart') .click(bind(this, this.emit, 'open', pattern));
  dom.find('.watch')        .click(bind(this, this.emit, 'watch', pattern));
  dom.find('.products')     .click(bind(this, this.emit, 'products', pattern));
  dom.find('.details')      .click(bind(this, this.emit, 'open', pattern));

  dom.find('.category')     .text( pattern.breakout? t('Ausgeborchen') : t('Ausgebildet') );
  dom.find('.type')         .text( t(pattern.type)       );
  dom.find('.headline part').text( t('auf')              );
  dom.find('.instrument')   .text( t(pattern.instrument) );
  dom.find('.watch')        .text( t('Beobachten')       );
  dom.find('.products')     .text( t('Produkte')         );
  dom.find('.details')      .text( t('Details')          );
};

clazz.inherit(Card, ee);

Card.prototype.render = function() {
  return this.dom;
}

module.exports = Card;

from component.

tj avatar tj commented on August 14, 2024

there wont be anything integrated, probably best that we just provide some option(s) per component. Maybe we just do stuff like:

exports.strings = {
  category: 'Category',
  ...
}

and reference those. There wont be mustache or anything built in but I wrote https://github.com/visionmedia/minstache to have super light-weight stand-alone view functions that we can compile beforehand

from component.

juliangruber avatar juliangruber commented on August 14, 2024

ok, that looks good too.

from component.

juliangruber avatar juliangruber commented on August 14, 2024

exports.strings won't work when there is data from an API that is to be translated. If a component e.g. should print a color's name, like Your chosen background color is black it needs to translate that on the fly.

3 possibilities:

  • assign the whole translation object to exports.strings: comp.strings = translations['en'] || clone(translations['en'])
  • translate strings in the api response: res.color = t(res.color)
  • let your api do the translation

With the passed t-function that is already covered.

from component.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.