Deleted articles cannot be recovered. Draft of this article would be also deleted. Are you sure you want to delete this article?
Railsã¢ããªãä½æããéãvalidateã®ã¡ãã»ã¼ã¸ãããã¿ã³ã®æè¨ãªã©ã¯é常è±èªã§è¡¨ç¤ºããã¦ãã¾ãï¼viewã®éå½¢ãè±èªã§ããããã§ããâ¦ï¼ æ¥æ¬äººãªã®ã§ãå½ç¶æ¥æ¬èªè¡¨ç¤ºã«ã¯ãããã¨ããã§ããããã®ã¾ã¾åãè¾¼ãã§ãã¾ãã®ã¯ããã¯ãä¿å®æ§ã«æ¬ ãã¾ããä½æãã人ã«ãããæè¨ã®æºããªã©ãçºçããã®ãåé¡ã§ãã ã¾ããå¤è¨èªå対å¿ãè¦éã«ããã¨ãåãç»é¢ãè¨èªã«åããã¦ä½æããã®ããä¿å®æ§ã«æ¬ ãã¾ãã Railsã®å¤è¨èªå対å¿ãçãè¾¼ã¿ã¾ãã Wikipediaã«ãã㨠æ å ±å¦çã«ãããå½éåã¨å°ååï¼ããããã 㨠ã¡ãããï¼ã¯ãã½ããã¦ã§ã¢ãéçºããç°å¢ã¨ã¯ç°ãªãç°å¢ãç¹ã«å¤å½ãç°æåã«é©åãããæ段ã§ããã å½éåï¼ã¢ã¡ãªã«è±èª: internationalization ã¤ã®ãªã¹è±èª: internationalisationãi18n) ã¯ãã½ããã¦ã§ã¢ã«æè¡çãªå¤æ´ãå ãããã¨
ä¸çã®éµä¾¿çªå·ãããããã詳ããè¦ã¦ããã¾ãããã æ¥æ¬ã®éµä¾¿çªå·ã¯7æ¡ æ¥æ¬ã¯ï¼æ¡ã®æ°åã§ãã 111-1111 ã¨ããããã«ã3æ¡ï¼4æ¡ã®çµåãã§ãã ã¢ã¡ãªã«ã®éµä¾¿çªå·ã¯9æ¡ ã¢ã¡ãªã«ã¯ï¼æ¡ã§ãã 5æ¡ - 4æ¡ã®æ°åã§è¨è¼ããã¾ãã ã«ããã®éµä¾¿çªå·ã¯6æ¡ N5X 1N7, M4W 2L1, V5X 4A4 ... 6æ¡ã®è±æ°åã§ãã 3ã4æ¡ã®éã«ã¹ãã¼ã¹ãããã®ãç¹å¾´ã§ãã ã¤ã®ãªã¹ã®éµä¾¿çªå·ã¯6æ¡ TN4 1TY, LS29 6SZ ... ã«ããã¨ä¼¼ã¦ãã¾ãã 6æ¡ã®è±æ°åã§ãã åæ§ã«ã3,4æ¡ã®éã«ã¹ãã¼ã¹ãããã¾ãã ä¸å½ã®éµä¾¿çªå·ã¯6æ¡ 215000, 200024 ... 6æ¡ã®æ°åã§ãã ã·ã³ã¬ãã¼ã«ã®éµä¾¿çªå·ã¯6æ¡ 247964, 408600 ... 6æ¡ã®æ°åã§ãã ãªã¼ã¹ãã©ãªã¢ã®éµä¾¿çªå·ã¯4æ¡ 3207, 6800 ... 4æ¡ã®æ°åã§ãã ãã³ã¬ãªã¼
rails6ã§rails-i18nã使ç¨ãã¦ããã©ã¡ã¼ã¿ã¼ã§è¡¨ç¤ºããè¨èªãåãæ¿ãã¦å¤è¨èªå¯¾å¿ãè¡ãã¾ã§ã®æé ãè¨è¿°ãã¦ã¾ããRailsã®ãã¼ã¸ã§ã³ã¯6.1.1ã使ç¨ãã¦ã¾ãã ç°å¢ OS CentOS Linux release 7.9.2009 (Core)Ruby 2.7.2Rails 6.1.1rbenv 1.1.2-40-g62d7798 rails-i18nã¤ã³ã¹ãã¼ã« Gemfileã«ä»¥ä¸ã追å ãã¦ã
ç°å¢ rails 5.2 ruby 2.5 æ¹é ã§ããã ãæ軽ã«æ¥è±å¯¾å¿ æ¦è¦ è¨èªåãæ¿ããã¿ã³ããããã¼ã«è¨ç½® ã³ã³ããã¼ã©ã¼å ã§ã»ãã·ã§ã³å¤æ°session[:locale]ãªã©ã«ãã±ã¼ã«æ å ±ãæ ¼ç´ before_action ã§åãã¼ã¸èªã¿è¾¼ã¿åã«è¨èªè¨å® ymlãã¡ã¤ã«ã¸è¨³æè¨å ¥ Viewãªã©ã§ä½¿ç¨ å®è£ 1. è¨èªåãæ¿ããã¿ã³ããããã¼ã«è¨ç½® ç°¡åã«åãæ¿ããã§ããããã«ãããã¼ã«ãã¿ã³è¨ç½®ãã¾ããã ãããã¼ã«ä»¥ä¸ãè¨ç½® <% if session[:locale] == "en" || session[:locale].blank? %> <%= link_to "/home/change_language/ja" do %> æ¥æ¬èª <% end %> <% elsif session[:locale] == "ja" %> <%= link_to "/home/ch
ããã«ã¡ã¯ããã¼ãã¼ã¨ã³ã¸ãã¢ã®ãããã§ãã æ¢åã®Railsã¢ããªãå½éåã¢ããªã«ã¬ãã«ã¢ããï¼ãã¼ã«ã©ã¤ãºï¼å¤è¨èªåï¼ããããï¼ Railsã¢ããªæ¨æºã®ã¨ã©ã¼ã¡ãã»ã¼ã¸ãè±èªã ããæ¥æ¬èªåãããï¼ ã¨ãããã¨ã§Rails I18nãç¨ãã¦å¤è¨èªåã«å¯¾å¿ããããã®æºåãè¡ãã¾ãã åºæ¬çã«Railsã¬ã¤ãã®Rails å½éå (i18n) APIã«æ²¿ã£ãå 容ã§ãã ä»åã¯ã https://www.foo.com/bar?locale=ja ã¨ããURL paramsãå ã«ç¿»è¨³è¨èªãå¤å¥ããæ¹æ³ãé¸æãã¾ãã æ¦ç¥ å¿ è¦ãã¡ã¤ã«ãä½æ Gemã®ã¤ã³ã¹ãã¼ã« è¨å®ã®æ¸ã込㿠ç°å¢ $ rails --version Rails 5.2.4.2 $ ruby --version ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin1
ãCSSãã§iframeè¦ç´ ãã¬ã¹ãã³ã·ã対å¿ãããã¾ãã¯ãCSSã§iframeè¦ç´ ãã¬ã¹ãã³ã·ã対å¿ãããæ¹æ³ã説æãã¾ããCSSãªã³ãªã¼ã§ãã¬ã¹ãã³ã·ã対å¿ããããã¨ãã§ãã¾ãã以ä¸ã®YouTubeã®åç»ã¯iframeè¦ç´ ã¨ãªã£ã¦ãã¾ãããããã説æããCSSã§ã¬ã¹ãã³ã·ã対å¿ããã¦ãã¾ãã Design for a Mobile MindHTML â iframeè¦ç´ ãã©ããããHTMLã®æ¹ã§ã¯ãã¬ã¹ãã³ã·ã対å¿ããããiframeè¦ç´ ãdivè¦ç´ ãªã©ã§ã©ãããã¾ããããããã«classå±æ§ãªã©ã§ååãã¤ãã¾ããiframeè¦ç´ ã¯ã§ããããµã¤ãºã®æå®ããã¦ããã¾ãã <div class="iframe-wrapper"> <iframe width="560" height="315" src="https://www.youtube.com/embed/xqviGwyy7y0?r
ç®ç æ¥æ¬èªå対å¿ããæã®ã¡ã¢ ä»å¾ãrailsãå¦ã¶æ¹ã«åãã¦ã®åèã«å½¹ç«ã¦ãã æ¡ä»¶ ruby 2.5.1 Rails 5.0.7 ãªã¹ã ããã©ã«ãã®è¨èªãæ¥æ¬èªã«è¨å®ãã gem 'rails-i18n'ãã¤ã³ã¹ãã¼ã« è¤æ°ã®ãã±ã¼ã«ãã¡ã¤ã«ãèªã¿è¾¼ã¾ããããpathãéã config/locales以ä¸ã«ãã±ã¼ã«ãã¡ã¤ã«ãé ç½® ja.ymlã«æ¥æ¬èªãè¨å®ãã è¨å®ããæ¥æ¬ã表示ããã æ§ã ãªè¨è¿°æ¹æ³ 1. ããã©ã«ãã®è¨èªãæ¥æ¬èªã«è¨å®ãã require_relative 'boot' require 'rails/all' Bundler.require(*Rails.groups) module BoardApp class Application < Rails::Application config.time_zone = 'Tokyo' config.active_
ã¯ããã« Railsã®ããã©ã«ãè¨èªã®æ¥æ¬èªåï¼2ãã¿ã¼ã³ï¼ å¤è¨èªã®ymlãã¡ã¤ã«ãå°å ¥(2ãã¿ã¼ã³) config/localesã§é層çã«å¤è¨èªãã¡ã¤ã«ã®ç®¡ç çè ã®ã¹ãã㯠Railså¦ç¿æ´ï¼4ã¶æ æ¡ä»¶ Rails 6.0.3.2 Ruby 2.6.6 ãã®ããééããªã©ãããå¯è½æ§ãããã®ã§éµåã¿å³ç¦! Railsã®ããã©ã«ãè¨èªã®æ¥æ¬èªåï¼2ãã¿ã¼ã³ï¼ ã©ã¡ããçæ¹ã®è¨å®ã§æ¥æ¬èªã®è¨èªè¨å®ã¯å®äºãã¾ãã 1. config/application.rbã«è¨å®æ å ±ã追å config/application.rbã«config.i18n.default_locale = :jaãè¨å ¥ãããã¨ã§æ¥æ¬èªãå©ç¨ã§ãã¾ãã :jaã®é¨åãä»ããã¼ã±ã«ãã¼ã«å¤ãããã¨ã§ä»ã®è¨èªã«è¨å®ãããã¨ãã§ãã¾ãã
Spring Bootã§ã¯application.propertiesã«è¨å®ãæ¸ãã°MessageSourceã¯ã©ã¹ããå¤è¨èªå¯¾å¿ãããã¡ãã»ã¼ã¸ãè¿ã£ã¦ãããããã ...ããã©ããããªãã¼ã·ã§ã³ã¨ã©ã¼ã¡ãã»ã¼ã¸ã¯å¤è¨èªåãã¦ãããªãã£ãã ç°¡åã«ããæ¹ãã¡ã¢ã£ã¦ããã åä½ç°å¢ Java 8 Spring Boot 1.3.2 å®éã«æ¸ããã³ã¼ã è¨å®ãã¡ã¤ã«ã®ç¨æ ã»ã¼åæè¨å®ã®ã¾ã¾ãè¨èªãã¡ã¤ã«ã¯i18nã®ä¸ã«ç½®ãããã£ãã®ã§ããã ãå¤æ´ã
i18nã¨å¼ã°ããå¤è¨èªåã®å¯¾å¿ãè¡ãã¾ãã ä»åã¯src/main/resourcesã®é ä¸ã«i18nãã©ã«ããä½æãããã®ä¸ã«ç¿»è¨³ãã¡ã¤ã«ãé ç½®ãã¾ãã SpringBootã¸è¨å® SringBootã¯ããã©ã«ãè¨å®ã§ãsrc/main/resourcesã®é ä¸ã«ããmessages.propertiesãã¡ã¤ã«ãè¦ã¾ãã ãã®ããã翻訳ãã¡ã¤ã«ã®é ç½®å ãapplication.ymlã«è¨å®ãã¾ãã 翻訳ãã¡ã¤ã«ã®é ç½® å ã»ã©è¨å®ãããã©ã«ãã«ç¿»è¨³ãã¡ã¤ã«ãé ç½®ãã¾ãã 翻訳ãã¡ã¤ã«ã¯messages_è¨èª.propertiesã§ãã ä¾) messages_ja.properties ãã®æã対象ã®è¨èªãã¡ã¤ã«ããªãå ´åç¨ã«ããã©ã«ã( messages.properties )ãé ç½®ããå¿ è¦ãããã¾ãã ç»é¢ã¸è¨å® 翻訳ãã¡ã¤ã«ã®ããããã£å¤ãç»é¢ã¸åãè¾¼ã¿ã¾ãã 以ä¸ã®ããã«åã
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}