我有一个关于复数函数的问题.在我看来,我有以下代码行.它传入具有一定数量投票的项目,以确定"投票"这个词是否应该复数.
<%= pluralize(item.votes, 'Vote') %>
Run Code Online (Sandbox Code Playgroud)
我的问题是我的观点传出了"投票"这个词,然后是一定数量的投票(item.votes).我只希望它传出"投票"这个词.非常感谢您的想法.
ruby-on-rails pluralize plural ruby-on-rails-3 ruby-on-rails-3.1
在使用Django模板复数过滤器的句子中定义的最佳方法是什么?例如:
<p>
Your item{{ items|length|pluralize }}
is/are
currently being processed and will ship soon.
</p>
Run Code Online (Sandbox Code Playgroud) 您好我需要根据值进行复数翻译,但无法找到如何做到这一点.
例如,我有变量peopleCount.
peopleCount = 1翻译应该是:英语:{{ peopleCount }} person likes this立陶宛语:{{ peopleCount }} zmogus tai megstapeopleCount超过1英文翻译将是:{{ peopleCount }} people like this.但对于立陶宛语翻译:
peopleCount是2到9之间或任何以这些数字结尾的数字,除了以第4个规则提供的数字结尾的数字(例如:225,249,210 <---这些是正确的数字.并且不正确的数字:215,250 ... ).这将是{{ peopleCount }} zmones tai megsta{{ peopleCount }} zmoniu tai megsta我该如何做到这一点?
我想%@ there are up to %i sun hours用正确的复数翻译字符串.
%@包含一天,%i太阳时.
这是我的Localizable.stringsdict档案:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>%@ there are up to %i sun hours</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@hours@</string>
<key>hours</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>i</string>
<key>zero</key>
<string>%@ there are no sun hours</string>
<key>one</key>
<string>There is one sun hour %@ </string>
<key>other</key>
<string>%@ there are up to %i sun hours</string>
</dict>
</dict>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)
这就是我所说的:
[NSString stringWithFormat:NSLocalizedString(@"%@ there are …Run Code Online (Sandbox Code Playgroud) 我正在使用Rails 5,我刚刚Media使用脚手架工具创建了一个模型.
rails g scaffold media name:string
Run Code Online (Sandbox Code Playgroud)
我有不同的名字和路线和视图等...
这是不正确的多元化,所以当我rake routes得到medium意想不到的路线,因此我在视图中遇到了不同的问题.
当我尝试使用时,<%= form_for @media do ..我抱怨了no method media_index_path.
我怎样才能解决它并且运行良好?
在此先感谢您的帮助.
对不起我的英语不好...
我有一个为西班牙开发的rails应用程序,因此,所有内容都是西班牙语,所以,我有一个搜索框在mysql数据库中搜索,所有行都是西班牙语,我想改进我的搜索,以允许用户以单数或复数形式搜索关键字,例如:
keyword: patatas
found: patata
keyword: veces
found: vez
keyword: vez
found: veces
keyword: actividades
found: actividad
Run Code Online (Sandbox Code Playgroud)
在英语中,在单一化和复数化方法的帮助下,这可能相对容易...
where `searching_field` like '%singularized_keyword%' or `searching_field` like '%pluralized_keyword%'
Run Code Online (Sandbox Code Playgroud)
但是,对于西班牙语....
一些帮助?
谢谢!
我正在尝试从rails 2迁移到rails 3.
我面临一个奇怪的问题.
整个应用程序似乎没有使表名复数.
Mysql ::错误:表'r_database.country_data'不存在:
但是我的桌子上有country_datas作为名字.
应用程序在rails 2中完美运行.
从Rail 3开始,我习惯这样做:
User.model_name.human count: 2 # "Users"
Run Code Online (Sandbox Code Playgroud)
这似乎在Rails 4中不起作用?
[1] base » User.model_name.human count: 2
=> "User"
Run Code Online (Sandbox Code Playgroud)
多元化一个简单的字符串似乎工作:
[2] base » "User".pluralize
=> "Users"
Run Code Online (Sandbox Code Playgroud)
知道这里有什么问题吗?
我知道你可以使用复数特征在Rails中复数一个单词.
pluralize (3, 'cat')
=> 3 cats
Run Code Online (Sandbox Code Playgroud)
但我想要做的是复数一个需要复数多个单词的句子.
There are <%= Cat.count %> cats
Run Code Online (Sandbox Code Playgroud)
问题是,如果只有一只猫.它会回来
There are 1 cats
Run Code Online (Sandbox Code Playgroud)
哪个没有意义.
应该说
There are x cats (if x is not 1)
There is 1 cat (if there is only 1)
Run Code Online (Sandbox Code Playgroud)
问题是,我无法弄清楚如何将其复数化,因为我们在这里有两个参数(是和猫).
任何帮助将不胜感激.
也许是这样的?
if Cat.count == 1
puts "There is 1 cat"
else
puts "There are #{Cat.count} cats"
end
Run Code Online (Sandbox Code Playgroud) EF Core 2.0 仍然有它的约定,它可以将复数变为单数,也可以将单数变为复数。因此,它肯定内置了多元化服务。
但是我找不到这个服务来将它用于其他目的。
在 EF 6 中,我会这样写:
using System.Data.Entity.Infrastructure.Pluralization;
// Then somewhere in code
var englishPluralizationService = new EnglishPluralizationService();
var singularCat = englishPluralizationService.Singularize("Cats");
Run Code Online (Sandbox Code Playgroud) pluralize ×10
ruby ×2
singular ×2
angularjs ×1
c# ×1
django ×1
inflection ×1
ios ×1
localization ×1
objective-c ×1
plural ×1
translation ×1