alexsk / mongoose-intl

Mongoose schema plugin for multilingual fields
MIT License
74 stars 31 forks source link

intl string inside array #2

Open ghost opened 8 years ago

ghost commented 8 years ago

Hi, if in a mongoose schema I have an array field of objects with intl fields, how can be set the label translations inside this array? The set method described in documentation post.set('title.all', { // defines all languages in one call using an object de: 'Another German title', fr: 'French title' }); applies to simple string fields not arrays. Any help?

alexsk commented 8 years ago

Array of objects with intl string fields works as expected using the following methods:

var librarySchema = new mongoose.Schema({
        books: [{ title: {type: String, intl: true}}],
});
var Library = mongoose.model('Library', librarySchema);

var lib = new Library();
lib.books.push({
    title: 'Default Language title'
});
lib.books[0].set('title.all', {
    en: 'English',
    de: 'German',
    fr: 'French'
});

while values can't be set/get using:

lib.books.set('0.title.all', {
    en: 'English',
    de: 'German',
    fr: 'French'
});
// or
lib.set('books.0.title.all', {
    en: 'English',
    de: 'German',
    fr: 'French'
});

That's a bug.

And the 2nd problem was found with arrays of strings:

var librarySchema = new mongoose.Schema({
    authors: [{type: String, intl: true}],
});
// or
var librarySchema = new mongoose.Schema({
    authors: {type: [String], intl: true},
});

It doesn't work at all here. Thank you for reporting on this.

hb-github commented 7 years ago

any solution here?

PixsaOJ commented 2 years ago

@alexsk I see on your profile that you are from Ukraine, I hope you are doing good. Stay strong brother <3

this issue will wait.