Skip to content

Commit

Permalink
Start localization
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoleNG18 committed Apr 13, 2024
1 parent c9349f0 commit 7218dd3
Show file tree
Hide file tree
Showing 12 changed files with 598 additions and 429 deletions.
35 changes: 35 additions & 0 deletions src/main/java/pmgkn/pescores/pescores/config/I18NConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package pmgkn.pescores.pescores.config;

import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.i18n.CookieLocaleResolver;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;

@Configuration
public class I18NConfig {
//bazirano na requesta razbira kakuv e ezika na koiyo iskame da se vidi saita
@Bean
public LocaleResolver localeResolver() {
CookieLocaleResolver clr = new CookieLocaleResolver();
clr.setCookieName("lang");
return clr;
}
//prihvashta koga potrebitelqt iska da smeni ezika
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
lci.setParamName("lang");
return lci;
}
//files with keys
@Bean
public MessageSource messageSource() {
ResourceBundleMessageSource resourceBundleMessageSource = new ResourceBundleMessageSource();
resourceBundleMessageSource.setBasename("i18n/messages");
resourceBundleMessageSource.setDefaultEncoding("UTF-8");
return resourceBundleMessageSource;
}
}
21 changes: 21 additions & 0 deletions src/main/java/pmgkn/pescores/pescores/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package pmgkn.pescores.pescores.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;

@Configuration
public class WebConfig implements WebMvcConfigurer {
private LocaleChangeInterceptor localeChangeInterceptor;

public WebConfig(LocaleChangeInterceptor localeChangeInterceptor) {
this.localeChangeInterceptor = localeChangeInterceptor;
}

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(localeChangeInterceptor);
}

}
29 changes: 29 additions & 0 deletions src/main/resources/i18n/messages.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
navbar_language=Language
navbar_login=Login
navbar_register=Sign up
navbar_add_school=How to add your school?

home_welcome=Welcome to PE Scores
home_if_dont_have=If you don't have an account - here.
home_if_have=If you have an account - here.
home_login=log in
home_register=sign up
login_login=Log in
login_email=Email
login_err=Invalid username or password.
login_pass=Password
signup_signup = Register
signup_confirm_pass = Confirm password
signup_pass = Password
signup_school = School
signup_email = Email
signup_last_name = Last name
signup_first_name = First name
err_name=Between 2 and 15 letters
err_email=Email should be unique
err_school=At least 15 symbols.
err_pass=At least 8 characters and 1 digit
err_confirm_pass=Passwords should match
29 changes: 29 additions & 0 deletions src/main/resources/i18n/messages_bg.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
navbar_language = Език
navbar_login = Вход
navbar_register = Регистрация
navbar_add_school = Как да добавите училището си?

home_welcome = Добре дошли!
home_if_dont_have = Ако нямате акаунт - тук
home_if_have = Ако имате акаунт - тук
home_login= влезте
home_register = регистрирайте се

login_login= Вход
login_email = Имейл
login_err=Невалидно име или парола
login_pass=Парола

signup_signup = Регистрация
signup_confirm_pass = Повторена парола
signup_pass = Парола
signup_school = Училище
signup_email = Имейл
signup_last_name = Фамилия
signup_first_name = Име

err_name=Между 2 и 15 букви
err_email=Имейлът трябва да бъде уникален
err_school=Поне 15 символа
err_pass=Поне 8 символа и поне 1 число
err_confirm_pass=Паролите трябва да съвпадат
19 changes: 19 additions & 0 deletions src/main/resources/static/css/fragments.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,25 @@ header img {
color: #d8d7fe;
}

select {
background-color: #d8d7fe;
color: #5d54c3;
border-color: #d8d7fe;
font-weight: 600;
font-size: 14px;
}

option {
font-weight: 600;
background-color: #d8d7fe;
color:#5d54c3;
}

option:checked {
background-color: #5d54c3;
color: #d8d7fe;
}

.navbar-buttons a {
cursor: pointer;
background-color: #d8d7fe;
Expand Down
25 changes: 19 additions & 6 deletions src/main/resources/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,21 @@

<nav class="navbar">
<ul class="navbar-buttons" sec:authorize="!isAuthenticated()">
<a th:href="@{/contact}">How to add your school?</a>
<a th:href="@{/users/login}">Log in</a>
<a th:href="@{/users/register}">Sign up</a>
<a th:href="@{/contact}" th:text="#{navbar_add_school}">How to add your school?</a>
<a th:href="@{/users/login}" th:text="#{navbar_login}">Log in</a>
<a th:href="@{/users/register}" th:text="#{navbar_register}">Register</a>
<a class="nav-item">
<form th:method="get">
<label class="text-white" th:text="#{navbar_language}" for="lang"></label>
<select
onchange="this.form.submit()"
id="lang"
name="lang">
<option value="en_US" th:selected="${#locale.toString()} == 'en_US'">English</option>
<option value="bg_BG" th:selected="${#locale.toString()} == 'bg_BG'">Български</option>
</select>
</form>
</a>
</ul>

<ul class="navbar-buttons" sec:authorize="isAuthenticated()">
Expand Down Expand Up @@ -54,9 +66,10 @@
<div sec:authorize="!isAuthenticated()" class="main-section-wrap">
<section class="main-section">
<div class="main-text">
<h3>Welcome to PE Scores.</h3>
<p>If you have an account - <a href="/users/login">Log in</a> here.</p>
<p>If you don't have an account - <a href="/users/register">Sign up</a> here.</p>
<h3 th:text="#{home_welcome}">Welcome to PE Scores</h3>
<!-- TODO:IF STAYS HERE-->
<!-- <p th:text="#{home_if_have}">If you have an account - <a href="/users/login" th:text="#{home_login}">Log in</a> here.</p>-->
<!-- <p th:text="#{home_if_dont_have}">If you don't have an account - <a href="/users/register" th:text="#{home_register}">Sign up</a> here.</p>-->
</div>
</section>
</div>
Expand Down
32 changes: 22 additions & 10 deletions src/main/resources/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,21 @@

<nav class="navbar">
<ul class="navbar-buttons" sec:authorize="!isAuthenticated()">
<a th:href="@{/contact}">How to add your school?</a>
<a th:href="@{/users/login}">Log in</a>
<a th:href="@{/users/register}">Sign up</a>
<a th:href="@{/contact}" th:text="#{navbar_add_school}">How to add your school?</a>
<a th:href="@{/users/login}" th:text="#{navbar_login}">Log in</a>
<a th:href="@{/users/register}" th:text="#{navbar_register}">Register</a>
<a class="nav-item">
<form th:method="get">
<label class="text-white" th:text="#{navbar_language}" for="lang"></label>
<select
onchange="this.form.submit()"
id="lang"
name="lang">
<option value="en_US" th:selected="${#locale.toString()} == 'en_US'">English</option>
<option value="bg_BG" th:selected="${#locale.toString()} == 'bg_BG'">Български</option>
</select>
</form>
</a>
</ul>

<ul class="navbar-buttons" sec:authorize="isAuthenticated()">
Expand Down Expand Up @@ -51,26 +63,26 @@
th:method="POST"
th:action="@{/users/login}"
th:object="${userLoginDto}">
<h3>Login</h3>
<h3 th:text="#{login_login}">Log in</h3>

<label for="email" class="label">Email</label>
<input type="text" placeholder="Email" id="email"
<label for="email" class="label" th:text="#{login_email}">Email</label>
<input type="text" th:placeholder="#{login_email}" id="email"
th:field="*{email}"
name="email"
class="input"/>

<label for="password" class="label">Password</label>
<input type="password" placeholder="Password"
<label for="password" class="label" th:text="#{login_pass}">Password</label>
<input type="password" th:placeholder="#{login_pass}"
name="password"
id="password" class="input"/>

<div class="form-group mt-1">
<div class="label-holder text-white d-flex justify-content-start">
<p th:if="${bad_credentials}" class="errors alert-danger errors-login">Invalid username or password.</p>
<p th:if="${bad_credentials}" class="errors alert-danger errors-login" th:text="#{login_err}">Invalid username or password.</p>
</div>
</div>

<button class="login-btn">Log In</button>
<button class="login-btn" th:text="#{login_login}">Log In</button>

</form>

Expand Down
57 changes: 34 additions & 23 deletions src/main/resources/templates/register.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,21 @@

<nav class="navbar">
<ul class="navbar-buttons" sec:authorize="!isAuthenticated()">
<a th:href="@{/contact}">How to add your school?</a>
<a th:href="@{/users/login}">Log in</a>
<a th:href="@{/users/register}">Sign up</a>
<a th:href="@{/contact}" th:text="#{navbar_add_school}">How to add your school?</a>
<a th:href="@{/users/login}" th:text="#{navbar_login}">Log in</a>
<a th:href="@{/users/register}" th:text="#{navbar_register}">Register</a>
<a class="nav-item">
<form th:method="get">
<label class="text-white" th:text="#{navbar_language}" for="lang"></label>
<select
onchange="this.form.submit()"
id="lang"
name="lang">
<option value="en_US" th:selected="${#locale.toString()} == 'en_US'">English</option>
<option value="bg_BG" th:selected="${#locale.toString()} == 'bg_BG'">Български</option>
</select>
</form>
</a>
</ul>

<ul class="navbar-buttons" sec:authorize="isAuthenticated()">
Expand Down Expand Up @@ -56,53 +68,52 @@
th:action="@{/users/register}"
th:object="${registerDto}">

<h3>Sign up</h3>
<h3 th:text="#{signup_signup}">Register</h3>

<div class="row-form">
<div class="element">

<label for="firstname" class="label">First name</label>
<label for="firstname" class="label" th:text="#{signup_first_name}">First name</label>
<input type="text"
name="firstName"
th:errorclass="is-invalid"
th:field="*{firstName}"
placeholder="First name"
th:placeholder="#{signup_first_name}"
id="firstname"
class="input"/>
<div class="invalid-feedback errors-register alert-danger"
th:each="err :${#fields.errors('firstName')}"
th:text="${err}"/>
th:each="err :${#fields.errors('firstName')}" th:text="#{err_name}"/>
</div>

<div class="element">
<label for="lastname" class="label">Last name</label>
<input type="text" placeholder="Last name"
<label for="lastname" class="label" th:text="#{signup_last_name}">Last name</label>
<input type="text"th:placeholder="#{signup_last_name}"
th:field="*{lastName}"
th:errorclass="is-invalid"
id="lastname" class="input"/>
<div class="invalid-feedback errors-register alert-danger"
th:each="err :${#fields.errors('lastName')}"
th:text="${err}"/>
th:text="#{err_name}"/>
</div>

</div>

<div class="row-form">

<div class="element">
<label for="email" class="label">Email</label>
<label for="email" class="label" th:text="#{signup_email}">Email</label>
<input
type="text" placeholder="Email"
type="text" th:placeholder="#{signup_email}"
th:field="*{email}"
th:errorclass="is-invalid"
id="email" class="input"/>
<div class="invalid-feedback errors-register alert-danger"
th:each="err :${#fields.errors('email')}"
th:text="${err}"/>
th:text="#{err_email}"/>
</div>

<div class="element">
<label for="school" class="label">School</label>
<label for="school" class="label" th:text="#{signup_school}">School</label>
<select id="school"
th:field="*{school}"
th:errorclass="is-invalid"
Expand All @@ -114,7 +125,7 @@ <h3>Sign up</h3>
</select>
<div class="invalid-feedback errors-register alert-danger"
th:each="err :${#fields.errors('school')}"
th:text="${err}"/>
th:text="#{err_school}"/>
</div>

</div>
Expand All @@ -123,30 +134,30 @@ <h3>Sign up</h3>

<div class="element">

<label for="password" class="label">Password</label>
<label for="password" class="label" th:text="#{signup_pass}">Password</label>
<input
type="password" placeholder="Password"
type="password" th:placeholder="#{signup_pass}"
th:field="*{password}"
th:errorclass="is-invalid"
id="password" class="input"/>
<div class="invalid-feedback errors-register alert-danger"
th:each="err :${#fields.errors('password')}"
th:text="${err}"/>
th:text="#{err_pass}"/>
</div>

<div class="element">
<label for="confirmpassword" class="label">Confirm Password</label>
<label for="confirmpassword" class="label" th:text="#{signup_confirm_pass}">Confirm Password</label>
<input
type="password"
th:field="*{confirmPassword}"
th:errorclass="is-invalid"
placeholder="Confirm password" id="confirmpassword" class="input"/>
th:placeholder="#{signup_confirm_pass}" id="confirmpassword" class="input"/>
<div class="invalid-feedback errors-register alert-danger"
th:each="err :${#fields.errors('confirmPassword')}"
th:text="${err}"/>
th:text="#{err_confirm_pass}"/>
</div>
</div>
<button type="submit" class="register-btn">Sign up</button>
<button type="submit" class="register-btn" th:text="#{signup_signup}">Sign up</button>

</form>

Expand Down
Loading

0 comments on commit 7218dd3

Please sign in to comment.