Skip to content

[UI] Add RTL support with CSSJanus#2678

Closed
Frenzie wants to merge 10 commits intoFreshRSS:masterfrom
Frenzie:rtl-janus
Closed

[UI] Add RTL support with CSSJanus#2678
Frenzie wants to merge 10 commits intoFreshRSS:masterfrom
Frenzie:rtl-janus

Conversation

@Frenzie
Copy link
Copy Markdown
Member

@Frenzie Frenzie commented Nov 19, 2019

This PR supersedes #2658 and fixes #673. It's a slightly different (automated) principle, which requires significantly less manual attention. The entire file is automatically processed and adjusted. It adds the new 19 kB library CSSJanus, but that's pretty much it.

I didn't really know where to put the auto-generator code; it should presumably be its own method somewhere. It sticks the generated files in themes/rtl and regenerates them if the original was modified more recently than the generated RTL file.

Screenshot_2019-11-19_16-23-08

Screenshot_2019-11-19 (10) ההזנות שלך · FreshRSS
Screenshot_2019-11-19 (10) ההזנות שלך · FreshRSSasf
Screenshot_2019-11-19 (10) ההזנות שלך · FreshRSSl;kj
Screenshot_2019-11-19 תצוגה · FreshRSS23423


This change is Reviewable

@Frenzie Frenzie added the UI 🎨 User Interfaces label Nov 19, 2019
@Alkarex Alkarex added this to the 1.16.0 milestone Nov 19, 2019
@Alkarex Alkarex added the I18n 🌍 Translations label Nov 19, 2019
}
$content = file_get_contents(PUBLIC_PATH . '/themes/' . $theme_id . '/' . $filename_ltr);
$rtl_content = CSSJanus::transform($content);
file_put_contents($path_rtl, $rtl_content);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this requires write access, we might consider treating the results as cache, and put them somewhere under ./data/
We have ext.php to serve files that are not directly exposed publicly, which we could generalise.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that makes sense.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Alkarex Unfortunately I just noticed a problem.

Ansum, for example, contains things like this:

background-image: url(icons/magnifier.svg);

The less elegant approach of just generating it locally and committing it all would be an easy way around that, but of course I wrote this PR to avoid such a thing. It's an action you can forget and it adds extra noise in commits/diffs.

One possible approach would be to copy the whole thing, along these lines (except in PHP instead of shell for Windows compatibility):

diff --git a/app/FreshRSS.php b/app/FreshRSS.php
index 14995d5e..4ca026e1 100644
--- a/app/FreshRSS.php
+++ b/app/FreshRSS.php
@@ -104,23 +104,27 @@ class FreshRSS extends Minz_FrontController {
                                        $filename_ltr = $file;
                                }
                                $filename_rtl = $filename_ltr . '.rtl.css';
-                               $path_ltr = PUBLIC_PATH . '/themes/' . $theme_id . '/' . $filename_ltr;
-                               $path_rtl = DATA_PATH . '/rtl/'. $theme_id . '.' . $filename_rtl;
+                               $path_ltr = PUBLIC_PATH . '/themes/' . $theme_id;
+                               $path_rtl = DATA_PATH . '/rtl/'. $theme_id;
+                               $path_full_ltr = $path_ltr . '/' . $filename_ltr;
+                               $path_full_rtl = $path_rtl . '/' . $filename_rtl;
 
-                               $filetime = @filemtime($path_ltr);
+                               $filetime = @filemtime($path_full_ltr);
                                $url = '/themes/' . $theme_id . '/' . $filename_ltr . '?' . $filetime;
 
                                if (_t('gen.dir') === 'rtl') {
-                                       if (!file_exists($path_rtl) || filemtime($path_rtl) < $filetime) {
+                                       if (!file_exists($path_full_rtl) || filemtime($path_full_rtl) < $filetime) {
+                                               `rm -rf $path_full_rtl`;
+                                               `cp -r $path_ltr $path_rtl`;
                                                // generate RTL CSS
                                                if (!class_exists('CSSJanus')) {
                                                        require_once LIB_PATH . '/lib_CSSJanus.php';
                                                }
-                                               $content = file_get_contents($path_ltr);
+                                               $content = file_get_contents($path_full_ltr);
                                                $rtl_content = CSSJanus::transform($content);
-                                               file_put_contents($path_rtl, $rtl_content);
+                                               file_put_contents($path_full_rtl, $rtl_content);
                                        }
-                                       $url = '/ext.php?f='. $theme_id . '.' . $filename_rtl . '&t=css&c=rtl&' . $filetime;
+                                       $url = '/ext.php?f='. $theme_id . '/' . $filename_rtl . '&t=css&c=rtl&' . $filetime;
                                }
 
                                Minz_View::prependStyle(Minz_Url::display($url));

That principle works fine, setting aside that the icon URLs still don't actually work at this point.

I looked around a bit and this PR simply puts them in the theme directory, but I figure having those writable isn't exactly desirable.

Also pinging @aledeg @marienfressinaud for their thoughts.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two things that bother me.

The first one is to put CSS theme files under the ./data folder (actually, there are a lot of files that I would not put in this folder, it's another non-critical subject). I was even considering dropping the ext.php and f.php mechanisms by replacing them by a dynamic system of "assets collection", to move all CSS and JS under the /p folder and to allow pre-processing. It's a long-term idea that I will not develop soon, but just to say that I don't mind if the server write files in the public folder: I find it's more logical.

The second thing is to do that in loadStylesAndScripts. Writing these files is a huge side-effect of the method. I would have done it at least in a different method of this class (and yet I don't think it's the ideal solution, but I can't find one for the moment ^^)

Last thing: I would like to have the feedback of someone who is used to RTL interfaces. I find the interfaces look pretty weird (but hey, it's normal since I never use RTL interfaces ^^) and I'm wondering if the solution is to simply reverse the rules or if there are trickier things to think about.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A note regarding were to place files: key aspects include whether the folder is writeable by the Web server, and whether the whole folder can be erased and replaced when there is a new FreshRSS version.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, I see what I wrote, haha. My apologies. I meant this:

Minor details like the arrows (which are in the wrong direction)
and
some missing UI elements.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown

@WaseemAlkurdi WaseemAlkurdi Nov 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Frenzie I've taken a look. Very awesome project! I'm thinking of deploying it sometime.
You're correct: the bottom (previous/next) arrows are indeed reversed. Other than that, no issues at all that I can see in the screenshots above vs. the demo.

Edit: Missing UI elements? I can't see any in the screenshots above.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WaseemAlkurdi I didn't see your edit. It's not the UI elements that are missing per se, but the icons on them (on the second and fourth screenshot).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Frenzie I had to stare at the screenshots for a couple minutes to even know what was missing! :-)
But true, the icons are missing (the toolbar and search bar, as far as I can see).

@marienfressinaud marienfressinaud changed the base branch from dev to master December 18, 2019 08:29
@Alkarex
Copy link
Copy Markdown
Member

Alkarex commented Dec 22, 2019

Let me know when this is ready for another review. As I am not familiar with RTL, I am only looking at potential negative side effects (e.g. performance) on LTR.

@Frenzie
Copy link
Copy Markdown
Member Author

Frenzie commented Dec 22, 2019

@Alkarex Unfortunately I've hit a roadblock on this approach as detailed here. So I suppose the main question is if we want it dynamically generated on the server or not.

@Alkarex
Copy link
Copy Markdown
Member

Alkarex commented Jan 7, 2020

For (future?) inspiration https://css-tricks.com/css-logical-properties/
We could also have some themes, which drop support for IE/Edge
https://caniuse.com/#feat=css-logical-props

@Frenzie
Copy link
Copy Markdown
Member Author

Frenzie commented Jan 7, 2020

I was aware of those when I started, yes. :-) Also see #2658 (comment)

@Frenzie
Copy link
Copy Markdown
Member Author

Frenzie commented Jan 18, 2020

@Alkarex @marienfressinaud @aledeg For the short term I think it would be best to change this into a simple CSSJanus call on the development machine, for example through make rtl, and to commit the result. Reworking the cache system to facilitate the likes of #446 and this (as described by @marienfressinaud in #2678 (comment)) is a time investment beyond the scope of what I'm interested in right now, and otherwise it'd just delay RTL a lot longer.

Since that shouldn't take long to draft up I'll probably open a third PR to show what that looks like, leaving this one as is. All of my effort here was intended to avoid putting it in the repo, but I don't see a clear weekend-hack path toward actually doing so right now.

@Frenzie Frenzie mentioned this pull request Jan 18, 2020
4 tasks
@Frenzie
Copy link
Copy Markdown
Member Author

Frenzie commented Mar 4, 2020

Merged #2776 instead.

@Frenzie Frenzie closed this Mar 4, 2020
@Frenzie Frenzie deleted the rtl-janus branch March 4, 2020 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

I18n 🌍 Translations UI 🎨 User Interfaces

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RTL support

4 participants