Giter Site home page Giter Site logo

Comments (5)

pyromaniac avatar pyromaniac commented on May 27, 2024

Yeah, I've got some Ideas. At first, you need to index your localized values. Assume you have User model with localized name:

class UsersIndex < Chewy::Index
  define_type User do
    # storing name translations as object
    field :name_translations, type: 'object'
    # you can even define custom properties for every translation (this goes first because of ES dynamic templates resolving rules)
    template 'name_translations.ru', type: 'string', index: 'analyzed', analyzer: 'custom_russian_analyzer'
    # in order to define every name translation properties, we are using dynamic templates
    template 'name_translations.*', type: 'string', index: 'analyzed', analyzer: 'custom_name_analyzer'

    # we are using `name_translations` field name instead of `name` to define type own methods
    # It will be useful if you will decide to use loaded and wrapped ES documents instead of loading AR objects.
    #   UsersIndex.query( .... ).first.name # will return name in current locale.
    def name
      name_translations[I18n.locale.to_s]
    end
  end
end

So, after indexing you have to query for data:

# you have to specify fields for current query according to current locale
UsersIndex.query(query_string: {fields: ["name_translations.#{I18n.locale}"], query: 'Jonny', default_operator: 'and', lenient: true})

That's it. I was recalling this from memory, so I'm not sure examples will work as is, you'll have to experiment.
I would appreciate if you will describe you adventure somewhere in wiki here. Would be a great first howto.

from chewy.

sasselin avatar sasselin commented on May 27, 2024

Thank you, it's work like a charm. My English is very poor. I am Quebecois. So I forker your example to make a multilang example. I give you permission to clone and put the documentation that you desire.

Free for you to do what you want it

https://github.com/sasselin/chewy_example_multilang

By the way, your solution work A1. I add the existing_filter for the model do not have all traduction.

from chewy.

pyromaniac avatar pyromaniac commented on May 27, 2024

https://github.com/sasselin/chewy_example_multilang/blob/master/app/chewy/page_index.rb#L17-L18
It will be better to use wildcard notation here, since this templates are similar: template 'title_translations.*', type: 'string', index: 'analyzed'

And thanks for example.

from chewy.

sasselin avatar sasselin commented on May 27, 2024

Yes I know, but in the futur i'll create a analyzer for each languages. Thank for your help. The gem is awesome! Very usefull.

from chewy.

pyromaniac avatar pyromaniac commented on May 27, 2024

Got it. Thanks for your testimonial :)

from chewy.

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.