简体   繁体   English

如何使用 swift 中的第一个后大写本地化字符串?

[英]How to localised string with first later capital in swift?

I am trying to localised string.我正在尝试本地化字符串。

In english i am getting like "Friday, Jun 26"在英语中,我越来越喜欢“Friday, Jun 26”

but in spanish its like "jueves, jun 25".但在西班牙语中,它就像“jueves, jun 25”。

first letter is small.第一个字母很小。 but I am trying to get just as English with first letter caps.但我正试图用首字母大写来获得与英语一样的英语。

Bellow is my code.贝娄是我的代码。

  let longDateFormatter = DateFormatter()
  longDateFormatter.dateFormat = "EEEE, MMM d"
  longDateFormatter.locale = Locale(identifier: "es")

is there any way to get date with first letter caps.有没有办法用首字母大写来获取日期。 Thanks for help/感谢帮助/

Apparently Spanish does not capitalize the names of months and days of the week like we do in English.显然西班牙语不像我们在英语中那样将月份和星期几的名称大写。 Thus the format you are getting is correct for Spanish, and you should stop trying to change it.因此,您获得的格式对于西班牙语是正确的,您应该停止尝试更改它。 (in essence, this is an x/y problem.) (本质上,这是一个 x/y 问题。)

See this link: https://www.spanishdict.com/answers/181002/do-months-need-to-be-capitalized-in-spanish#:~:text=Spanish%20does%20NOT%20capitalize%3A&text=%3F-,Calendar%3A%20Names%20of%20the%20days%20of%20the,and%20months%20of%20the%20year.&text=%3F-,Nationality%3A%20Although%20names%20of%20countries%20and%20cities%20are%20capitalized%2C%20words,derived%20from%20them%20are%20not .请参阅此链接: https://www.spanishdict.com/answers/181002/do-months-need-to-be-capitalized-in-spanish#:~:text=Spanish%20does%20NOT%20capitalize%3A&text=% 3F-,日历%3A%20Names%20of%20the%20days%20of%20the,and%20months%20of%20the%20year.&text=%3F-,Nationality%3A%20Although%20names%20of%20countries%20and%20cities %20are%20capitalized%2C%20words,derived%20from%20them%20are%20not .

If you want to do something different than the correct localization for Spanish you will need to take the output from the Spanish localization and manipulate it.如果您想做与正确的西班牙语本地化不同的事情,您需要从西班牙语本地化中获取 output 并对其进行操作。 You could simply use longDateFormatter.string(from: date).capitalized , which would capitalize every word in the resulting date string.您可以简单地使用longDateFormatter.string(from: date).capitalized ,它将大写生成的日期字符串中的每个单词。

let longDateFormatter = DateFormatter()
longDateFormatter.dateFormat = "EEEE, MMM d"
longDateFormatter.locale = Locale(identifier: "es")

let output = longDateFormatter.string(from: Date()).capitalized
print(output)

Yields产量

Viernes, Jun 26维尔内斯,6 月 26 日

But again, that is the WRONG way to display dates in Spanish.但同样,这是用西班牙语显示日期的错误方式。 It is every bit as wrong as displaying "friday, june 26" in English.这就像用英文显示“friday, june 26”一样错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM