emberjs / ember-inflector

ember-inflector goal is to be rails compatible.
MIT License
106 stars 81 forks source link

Irregular inflector behavior #110

Open escobera opened 7 years ago

escobera commented 7 years ago

Hello there,

I have these rules (among others) in my app.

inflector.irregular('arma-branca', 'armas-brancas');
inflector.irregular('acessorio-arma-branca', 'acessorios-armas-brancas');

With this config I get this result: selection_006

It seems the second irregular rule is never met, this line looks like the culprit. It checks for the end of the rule, so, strings ending the same way can respond wrongly.

Another thing I notice is that this code makes the irregular declaration order specific. If I invert the order like so:

inflector.irregular('acessorio-arma-branca', 'acessorios-armas-brancas');
inflector.irregular('arma-branca', 'armas-brancas');

I get the right result: selection_007

Can we make the irregulars check for the whole expression first?

oskarrough commented 7 years ago

I'm hoping my issue is related. Here's a failed attempt to pluralize human as humans.

inflector.irregular('human', 'humans');
console.log(inflector.pluralize('human')); // --> "humen"
tomoguisuru commented 7 years ago

I'm having a similar issue but with uncountable The uncountable rule seems to be applied to anything that has settings in rather than just for the specific instance listed.

Example.

Inflector.inflector.uncountable('settings')
Models
|- settings.js
|- bolo-setting.js

expected behavior settings is uncountable but bolo-setting is countable

This is causing an issue when I do the following

this.store.query('bolo-setting', { org_id: 1 });

which results in the following error message

Error: Assertion Failed: The response to store.query is expected to be an array but it was a single record. Please wrap your response in an array or usestore.queryRecordto query for a single record.

Removing the Uncountable rule corrects the issue for the bolo-setting model but causes issues for the setting model

I discovered this issue when updating to Ember-CLI 2.9.0 from Ember-CLI 1.13.13 and removing the Ember inflector per the deprecations

brunowego commented 7 years ago

Yep, same issue here.

import Inflector from 'ember-inflector';

export function initialize() {
  Inflector.inflector.irregular('human', 'humans'); // FIXME:
}

export default {
  name: 'inflectors',
  initialize
};

On backend:

ActiveSupport::Inflector.inflections do |inflect|
  inflect.irregular 'human', 'humans'
end
sandstrom commented 3 years ago

Is this an inconsistency between this repo and Rails inflector API?

If not, then it's better to use the API to make your own adjustments. The goal of this project is to provide a base-set that mirrors Rails inflector API.