From 30c00a864cd2e4af69b8b44e32ed3e5a29514849 Mon Sep 17 00:00:00 2001 From: Felipe Mateus Date: Sat, 15 Mar 2025 21:22:52 -0300 Subject: [PATCH] translate profile --- .../partials/profile/ProfileFeed.vue | 28 +++---- .../partials/profile/ProfileSidebar.vue | 16 ++-- resources/assets/js/app.js | 81 ++++++++++++------- resources/assets/js/components/Profile.vue | 34 ++++---- resources/lang/en/web.php | 18 +++++ resources/lang/pt/web.php | 18 +++++ 6 files changed, 128 insertions(+), 67 deletions(-) diff --git a/resources/assets/components/partials/profile/ProfileFeed.vue b/resources/assets/components/partials/profile/ProfileFeed.vue index c6c69efb0..748ec5a90 100644 --- a/resources/assets/components/partials/profile/ProfileFeed.vue +++ b/resources/assets/components/partials/profile/ProfileFeed.vue @@ -8,7 +8,7 @@ :class="[ tabIndex === 1 ? 'active' : '' ]" @click="toggleTab(1)" > - Posts + {{ $t("profile.posts")}} {{ $t('profile.editProfile') }} - My Portfolio + {{ $t("profile.myPortifolio") }} NEW @@ -421,10 +421,10 @@ }, getJoinedDate() { - let d = new Date(this.profile.created_at); - let month = new Intl.DateTimeFormat("en-US", { month: "long" }).format(d); - let year = d.getFullYear(); - return `${month} ${year}`; + return new Date(this.profile.created_at).toLocaleDateString(this.$i18n.locale, { + year: 'numeric', + month: 'long', + }); }, follow() { diff --git a/resources/assets/js/app.js b/resources/assets/js/app.js index 945834165..a3b36eec9 100644 --- a/resources/assets/js/app.js +++ b/resources/assets/js/app.js @@ -1,3 +1,5 @@ +import VueI18n from 'vue-i18n'; + require('./polyfill'); window._ = require('lodash'); window.Popper = require('popper.js').default; @@ -19,7 +21,7 @@ if (token) { window.App = window.App || {}; window.App.redirect = function() { - document.querySelectorAll('a').forEach(function(i,k) { + document.querySelectorAll('a').forEach(function(i,k) { let a = i.getAttribute('href'); if(a && a.length > 5 && a.startsWith('https://')) { let url = new URL(a); @@ -31,7 +33,23 @@ window.App.redirect = function() { } window.App.boot = function() { - new Vue({ el: '#content'}); + Vue.use(VueI18n); + + let i18nMessages = { + en: require('./i18n/en.json'), + pt: require('./i18n/pt.json'), + }; + let locale = document.querySelector('html').getAttribute('lang'); + + const i18n = new VueI18n({ + locale: locale, // set locale + fallbackLocale: 'en', + messages: i18nMessages +}); + new Vue({ + el: '#content', + i18n, + }); } window.addEventListener("load", () => { @@ -67,8 +85,8 @@ window.App.util = { console.log('Unsupported method.'); }), }, - time: (function() { - return new Date; + time: (function() { + return new Date; }), version: 1, format: { @@ -79,29 +97,34 @@ window.App.util = { return new Intl.NumberFormat(locale, { notation: notation , compactDisplay: "short" }).format(count); }), timeAgo: (function(ts) { - let date = Date.parse(ts); - let seconds = Math.floor((new Date() - date) / 1000); - let interval = Math.floor(seconds / 63072000); - if (interval >= 1) { - return interval + "y"; - } - interval = Math.floor(seconds / 604800); - if (interval >= 1) { - return interval + "w"; - } - interval = Math.floor(seconds / 86400); - if (interval >= 1) { - return interval + "d"; - } - interval = Math.floor(seconds / 3600); - if (interval >= 1) { - return interval + "h"; - } - interval = Math.floor(seconds / 60); - if (interval >= 1) { - return interval + "m"; - } - return Math.floor(seconds) + "s"; + let date = new Date(ts); + let now = new Date(); + let seconds = Math.floor((now - date) / 1000); + let interval = Math.floor(seconds / 31536000); + if (interval >= 1) { + return new Intl.RelativeTimeFormat('pt', { numeric: 'auto', style: 'short' }).format(-interval, 'year'); + } + interval = Math.floor(seconds / 2592000); + if (interval >= 1) { + return new Intl.RelativeTimeFormat('pt', { numeric: 'auto', style: 'short' }).format(-interval, 'month'); + } + interval = Math.floor(seconds / 604800); + if (interval >= 1) { + return new Intl.RelativeTimeFormat('pt', { numeric: 'auto', style: 'short' }).format(-interval, 'week'); + } + interval = Math.floor(seconds / 86400); + if (interval >= 1) { + return new Intl.RelativeTimeFormat('pt', { numeric: 'auto', style: 'short' }).format(-interval, 'day'); + } + interval = Math.floor(seconds / 3600); + if (interval >= 1) { + return new Intl.RelativeTimeFormat('pt', { numeric: 'auto', style: 'short' }).format(-interval, 'hour'); + } + interval = Math.floor(seconds / 60); + if (interval >= 1) { + return new Intl.RelativeTimeFormat('pt', { numeric: 'auto', style: 'short' }).format(-interval, 'minute'); + } + return new Intl.RelativeTimeFormat('pt', { numeric: 'auto', style: 'short' }).format(-seconds, 'second'); }), timeAhead: (function(ts, short = true) { let date = Date.parse(ts); @@ -145,9 +168,9 @@ window.App.util = { tag = '/i/redirect?url=' + encodeURIComponent(tag); } - return tag; + return tag; }) - }, + }, filters: [ ['1984','filter-1977'], ['Azen','filter-aden'], diff --git a/resources/assets/js/components/Profile.vue b/resources/assets/js/components/Profile.vue index 991d4ab62..36c2a3dac 100644 --- a/resources/assets/js/components/Profile.vue +++ b/resources/assets/js/components/Profile.vue @@ -16,7 +16,7 @@
-

You are blocking this account

+

{{ $t("profile.blocking")}}

Click here to view profile

@@ -49,7 +49,7 @@

{{formatCount(profile.statuses_count)}}

-

Posts

+

{{ $t("profile.posts")}}

@@ -57,7 +57,7 @@

{{formatCount(profile.followers_count)}}

-

Followers

+

{{ $t("profile.followers")}}

@@ -65,7 +65,7 @@

{{formatCount(profile.following_count)}}

-

Following

+

{{ $t("profile.following")}}

@@ -86,7 +86,7 @@

@@ -106,7 +106,7 @@ - Edit Profile + {{ $t("profile.editProfile") }} @@ -117,19 +117,19 @@
{{formatCount(profile.statuses_count)}} - Posts + {{ $t("profile.posts")}}
@@ -141,11 +141,11 @@

{{formatWebsite(profile.website)}}

- Admin + {{ $t("profile.admin") }} - Follows You + {{ $t("profile.followYou") }} - Joined {{joinedAtFormat(profile.created_at)}} + {{$t("profile.joined")}} {{joinedAtFormat(profile.created_at)}}

@@ -156,7 +156,7 @@

- +