Skip to content

Instantly share code, notes, and snippets.

Avatar

Manatsawin Hanmongkolchai whs

View GitHub Profile
View machine.js
Machine({
id: 'loading',
initial: 'hide',
states: {
hide: {
on: {
SHOW_NOW: 'show',
SHOW: {
actions: send('SHOW_NOW', { delay: 50, id: 'show' }),
},
View migrate.js
// from this
I18n.t(`business.${domain}.call`)
// to this
switch(domain){
case Domain.FOOD:
return I18n.t('business.FOOD.call')
case Domain.BEAUTY:
return I18n.t('business.BEAUTY.call')
}
View importinjection.js
t.importDeclaration(
[t.importDefaultSpecifier(t.identifier('th'))],
t.stringLiteral('file'),
)
View rewritealert.js
path.replaceWith(
t.callExpression(t.identifier('alert'), [
t.stringLiteral('Hello world')
])
)
View basebabel.js
export default function({ types: t }) {
return {
visitor: {
// visitor contents
}
};
};
View final.js
import I18n from 'common/I18n'
import TH from 'th/category.gyoza-restaurants'
import EN from 'en/category.gyoza-restaurants'
console.log(I18n.t({
th: TH,
en: EN,
}))
View currentlocale.js
import I18n from 'common/I18n'
console.log(I18n.t('category.gyoza-restaurants'))
View babel-injectimport.js
const importSpecifier = path.scope.generateUidIdentifier('th')
const importDeclaration = this.t.importDeclaration(
[this.t.importDefaultSpecifier(importSpecifier)],
this.t.stringLiteral('lang/th/file.yaml?' + this.resourceQuery),
)
program.unshiftContainer('body', importDeclaration)
View babel-quasiquote1.js
import template from 'babel-template'
const I18n$tCall = template('I18n.$t({th: TH, en: EN})')
export default function({types: t}){
return {
visitor: {
CallExpression(path) {
// ...
View babel1.js
export default function({types: t}){
return {
visitor: {
CallExpression(path) {
const node = path.node
// เช็คว่าเป็น I18n.t จริง
if (
!node.callee.object ||
node.callee.object.name !== 'I18n' ||
node.callee.property.name !== 't'