根据用户名的最后一个字母更改文本 [英] Changing text based on the final letter of user name

查看:25
本文介绍了根据用户名的最后一个字母更改文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的系统中,用户会注册他们的名字.在系统使用的自然语言中,名称的结尾取决于其用途,例如:

In my system, users will register their names. In the natural language the system is used with, names end differently depending its use, such as:

  • 谁:姓氏"
  • 与谁:"namai surnamai"

因此,我需要在某些地方更改@provider_user.name 的结尾;如果以e结尾,则将e替换为ai.

Due to this, I need to change the ending of @provider_user.name in some places; if it ends with e, replace e with ai.

我的 HTML 超薄代码是:

My HTML slim code is:

= render partial: 'services/partials/messages/original_message', locals: { header: t('html.text.consultation_with.for_provider', name: @provider_user.name)

它从 yml 文件中获取文本并使用 @provider_user.name.

It takes text from a yml file and uses @provider_user.name.

有什么建议可以解决这个问题吗?

Any suggestions to work this around?

推荐答案

试试这个,简单的单行代码

Try this, simple single line code

@provider_user.name.split.map {|w| (w.end_with?('e') ? (w.chomp(w[w.length - 1]) + 'ai') : w) }.join(" ")

我确定,它会将"name surname" 转换为"namai surnamai".

I am sure, it will convert "name surname" to "namai surnamai".

在其他情况下...

@provider_user.name.split.map {|w| (w.end_with?('e') ? (w.chomp(w[w.length - 1]) + 'ai') : (w.end_with?('us') ? (w.chomp(w[w.length - 1]) + 'mi') : (w.end_with?('i') ? (w.chomp(w[w.length - 1]) + 'as') : w))) }.join(" ")

这篇关于根据用户名的最后一个字母更改文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆